pencil.visu.pv_volume_plotter ============================= .. py:module:: pencil.visu.pv_volume_plotter .. autoapi-nested-parse:: `pv_volume_plotter.py` defines multiple different plotting routines for volume data from Pencil code VAR files. This includes methods such as: * scalars --- plots only scalar values on the plotter. Furthermore, scalars can be just 2D surfaces, or a volume rendering (only in cartesian coordinates) or 3-orthogonal slices defined by the center of the 3 slices. * vectors --- Vectors can be overlayed on to the scalar data. Vectors can be either constant in size or scaled by the magnitude of the vector field or the values on the scalar data. * streamlines --- Similarly to vectors, streamlines can be overlayed on to the scalar data. The radius of the streamlines can be scaled e.g. by the cartesian norm of the vector field. In addition, a colormap can be applied on to the streamline tubes. In addition, there are multiple source point sampling strategies for the vector field visualization methods (vectors|streamlines) such as: * random points in a volume * points on the surface of the volume, useful if streamlines are set to be constrained on to the surface (by setting parameter `surface_streamlines`) * points on a plane that slices through the volume * points on 3-orthogonal planes that slice through the volume * isosurfaces --- Plots isosurfaces defined by its isovalues. These can be either manually set or calculated automatically between the min max range of the supplied scalars. Furthermore, a moving isovalue gif can be generated that moves from first isovalue to last and back showing an moving representation of the isosurfaces. For usage examples and tutorials, see Pyvista3DPlot docstring! Requirements ------------ * sklearn * tqdm * numpy * pyvista (should be at least >= 0.31.3) All of these can be installed by: ``` pip3 install ``` .. warning:: I have experienced issues with volume rendering when using linux in VirtualBox due to missing 3D acceleration. HyperV seems to be able to access system hardware better and works on that. In my case I have a dedicated NVIDIA GPU - with different system hardware volume rendering might start throwing VTK warnings/errors and OpenGL related issues. .. rubric:: Notes - Note! In order for `streamlines_from_source()` to work you need to update PyVista to the latest version (at the moment 0.31.3) Known Issues ------------ - Interactive plotting windows have trouble closing sometimes - based on pyvista Github this is a known issue in the VTK source. Attributes ---------- .. autoapisummary:: pencil.visu.pv_volume_plotter.REASONS_FOR_TERMINATION pencil.visu.pv_volume_plotter.SAMPLING_METHODS Classes ------- .. autoapisummary:: pencil.visu.pv_volume_plotter.Plot3DSettings pencil.visu.pv_volume_plotter.Pyvista3DPlot Functions --------- .. autoapisummary:: pencil.visu.pv_volume_plotter.printTerminationReasons pencil.visu.pv_volume_plotter.meshSamplingMethods Module Contents --------------- .. py:data:: REASONS_FOR_TERMINATION .. py:data:: SAMPLING_METHODS :value: ['surface points', 'points', 'slice', 'slice orthogonal', 'default'] .. py:function:: printTerminationReasons(arr, plotter, add_to_image=False) .. py:function:: meshSamplingMethods(method, mesh, surface_mesh, n_points=100, normal='x', origin=None, set_seed_1=False, alwaysReturnList=False, get_arrays=False) .. py:class:: Plot3DSettings Class holding all plot customization parameters for the Pyvista3DPlot class. NOTE! See Pyvista3DPlot docstrings for documentation on the parameter tests. :param title: Title text to be added to the upper left corner. If set to '' title is set automatically to contain some information, i.e. datadir, scalar key and vector keys. If you want title to be empty, set it to e.g. ' ' :type title: str :param title_font_size: Font size for the title text :type title_font_size: int :param n_points: Total number of source points (vectors | streamlines) :type n_points: int :param set_seed_1: If True, random seed is set to one, all sampled source points are the same :type set_seed_1: bool :param imageformat: Any Python Pillow compatible image format, 'png', 'jpeg', etc. :type imageformat: str :param off_screen: Plotting done on screen or off screen? :type off_screen: bool :param window_size: Window size. :type window_size: tuple or list :param method: Sampling method, how source points for vectors / streamlines are sampled: 1.'surface points' --- random sampled points from the surface of the mesh 2. 'points' --- random sampled points in the whole mesh 3. 'slice' --- random sampled points on a slice defined by normal and an origin 4. 'slice_orthogonal' --- random sampled points on 3 orthogonal slices defined by origin 5. 'default' --- only to be used with streamlines, randomly samples mesh in a sphere given radius. :type method: str :param show_axes: Show axes for the plot :type show_axes: bool :param show_grid: Shows a grid on the plotter. :type show_grid: bool :param scalars_norm: Either 'log' or None :type scalars_norm: str :param override_log: If False, and scalar_key contains 'ln' parameter scalars_norm is automatically set to None. Else if scalar_key does not contain 'ln', scalar_norm is set to 'log'. If True, scalars_norm is kept to whatever user has set it to. :type override_log: bool :param background_color: Either a string e.g. 'white', 'black' or 'gray'. Also can be a three int RGB tuple e.g (255, 255, 255) :type background_color: str or 3-tuple of ints :param Widgets: :param -------: :param add_volume_opacity_slider: Adds a slider widget controlling parameter `volume_opacity`. Only applies when `mesh_type=="volume"`, i.e. volume rendering enabled. :type add_volume_opacity_slider: bool :param widget_type: Both of the available widget methods show an "arrow" that can be used to choose the angle of the sliced plane. Furthermore the plane itself can be moved up and down in the whole volume. Available widget types are: 1) 'clip slice' --- Only shows the current slice, noticeably faster than clip box. 2) 'clip box' --- Shows the current slice + the rest of the data "below" the slice. 3) 'plane vectors' --- Similar to 'clip box' except also vectors are added on to the slice. The vectors can be controlled by changing Plot3DSettings vectors parameters. 4) 'plane streamlines' --- same as plane vectors but with streamlines instead. :type widget_type: type :param Camera: :param ------: :param camera_centre: Coordinates for the centre of the camera. :type camera_centre: tuple of 3 floats :param focal_point: Coordinates for the camera focal point :type focal_point: tuple of 3 floats :param view_up: Vector defining up-direction of the camera. By default (0,0,1) i.e. "up" (z-direction). :type view_up: tuple of 3 floats :param zoom_factor: Zoom multiplier added to the camera. Larger the value, the more it zooms in. :type zoom_factor: float :param Streamlines: :param -----------: :param tube_radius: Radius for stream tubes :type tube_radius: float :param show_source: Show source points for streamlines :type show_source: bool :param surface_streamlines: If true streamlines are confined to a 2D surface :type surface_streamlines: bool :param stream_params: Any parameters pyvista streamlines_from_source() takes in OTHER THAN `surface_streamlines` and `vectors`. The following is the Pyvista's own documentation on the pyvista.streamlines_from_source, see link for documentation after the list: * integrator_type The integrator type to be used for streamline generation. The default is Runge-Kutta45. The recognized solvers are: RUNGE_KUTTA2 (2), RUNGE_KUTTA4 (4), and RUNGE_KUTTA45 (45). Options are 2, 4, or 45. Default is 45. * integration_direction Specify whether the streamline is integrated in the upstream or downstream directions (or both). Options are 'both', 'backward', or 'forward'. * initial_step_length Initial step size used for line integration, expressed in length unitsL or cell length units (see step_unit parameter). either the starting size for an adaptive integrator, e.g., RK45, or the constant / fixed size for non-adaptive ones, i.e., RK2 and RK4). * step_unit Uniform integration step unit. The valid unit is now limited to only LENGTH_UNIT ('l') and CELL_LENGTH_UNIT ('cl'). Default is CELL_LENGTH_UNIT: 'cl'. * min_step_length Minimum step size used for line integration, expressed in length or cell length units. Only valid for an adaptive integrator RK45. * max_step_length aximum step size used for line integration, expressed in length or cell length units. Only valid for an adaptive integrator RK45. * max_steps Maximum number of steps for integrating a streamline. * terminal_speed Terminal speed value, below which integration is terminated. * max_error Maximum error tolerated throughout streamline integration. * max_time Specify the maximum length of a streamline expressed in LENGTH_UNIT. * compute_vorticity Vorticity computation at streamline points (necessary for generating proper stream-ribbons using the vtkRibbonFilter. * interpolator_type Set the type of the velocity field interpolator to locate cells during streamline integration either by points or cells. The cell locator is more robust then the point locator. Options are 'point' or 'cell' (abbreviations of 'p' and 'c' are also supported). * rotation_scale This can be used to scale the rate with which the streamribbons twist. The default is 1 See https://docs.pyvista.org/core/filters.html?highlight=streamlines_from_source#pyvista.DataSetFilters.streamlines_from_source for more details on the parameters. Note that if stream_params is None the following defaults are set: >>> self.stream_params = { 'max_steps': 1000, 'max_time': 1e60, 'terminal_speed': 1e-60, 'integration_direction': 'both', 'compute_vorticity': False, 'integrator_type': 45, } :type stream_params: dict :param The following parameters are used if method == 'default'. Then streamline source points are: :param initialized from a sphere of radius source_radius and with center source_center.: :param source_radius: See description above. Radius for the sphere from which source points are sampled. :type source_radius: float :param source_center: Should be a tuple of 3 floats. Center for the sphere where source points are sampled from. :type source_center: tuple :param stream_variable_radius: Enable variable radius on the streamlines. Name of the data array used to scale the radius, either 'vector magnitude', 'scalars' or None :type stream_variable_radius: str :param stream_radius_factor: Multiplicative factor for the stream variable tube radius scaling. :type stream_radius_factor: float :param Vectors: :param -------: :param vector_scaling: Scaling method for vectors, options: 1. None --- no scaling 2. 'scalars' --- scaled based on scalars no the mesh 3. 'magnitude' --- scaled based on vector magnitude :type vector_scaling: str :param vector_factor: Multiplicative scaling for vectors :type vector_factor: float :param vector_max: Maximum value for vector magnitude scaling. If None, set automatically to mean + one standard deviation :type vector_max: float :param Mesh: :param ----: :param show_mesh: Whether to show the mesh or not :type show_mesh: bool :param mesh_type: Rendering type for mesh, options: "volume", "orthogonal slices" or "surface" :type mesh_type: str :param slice_pos: Applies if mesh_type=='orthogonal slices'. 3-tuple of floats (x,y,z) where - x = The X location of the YZ slice - y = The Y location of the XZ slice - z = The Z location of the XY slice :type slice_pos: tuple :param volume_opacity: Value between [0,1]. 0 corresponds to "not see through" i.e. opacity=1 and 1 "see through" i.e. opacity=0. In reality it is not that straight forward since this is handled automatically by volume renderer. What this parameter does is that `pyvista.add_volume parameter` `unit_opacity_distance` is set to value `mesh.length * volume_opacity`. See pyvista Documentation for more information on `unit_opacity_distance`. The default parameter 1/25 = 0.04 seems to work fairly well. :type volume_opacity: float :param culling: Does not render faces that are culled. Options are 'front' or 'back'. This can be helpful for dense surface meshes, especially when edges are visible, but can cause flat meshes to be partially displayed. By default None, i.e. no culling applied. :type culling: str :param Scalarbar: :type Scalarbar: General :param ------------------: :param vertical_sbar: Scalarbar vertical or horizontal :type vertical_sbar: bool :param cbar_width: Width as a percentage, between 0 and 1 :type cbar_width: float :param cbar_height: Height as a percentage, between 0 and 1 :type cbar_height: float :param cbar_title_font: Title font size for scalarbar title. :type cbar_title_font: int :param cbar_label_font: Label font size for scalarbar labels. :type cbar_label_font: int :param n_colors: Number of colors for the colorbar. :type n_colors: int :param _sbar_args: INTERNAL VALUE, SHOULD NOT BE USED :type _sbar_args: dict :param annotation_color: Color for the annotations, i.e. scalarbar tick texts etc. :type annotation_color: str :param Scalarbar: :type Scalarbar: Mesh :param ---------------: :param scalar_sbar_title: Title for the scalarbar for the mesh scalars. :type scalar_sbar_title: str :param show_mesh_sbar: Show scalarbar for the scalars on the mesh :type show_mesh_sbar: bool :param mesh_opacity: Opacity for the mesh :type mesh_opacity: float :param mesh_cmap: matplotlib compatible colormap for the mesh :type mesh_cmap: str :param scalar_sbar_pos_x: The percentage (0 to 1) along the window's horizontal direction to place the bottom left corner of the colorbar. If None it is placed automatically. :type scalar_sbar_pos_x: float :param scalar_sbar_pos_y: The percentage (0 to 1) along the window's vertical direction to place the bottom left corner of the colorbar. If None it is placed automatically. :type scalar_sbar_pos_y: float :param Scalarbar: :type Scalarbar: Vectors | Streamlines :param --------------------------------: :param field_sbar_title: Title for the scalarbar for the mesh field (vectors|streamlines). :type field_sbar_title: str :param show_field_sbar: Show scalarbar for the vectors on the mesh (streamlines/vectors) :type show_field_sbar: bool :param field_opacity: Opacity for the plotted streamlines / vectors :type field_opacity: float :param field_cmap: Colormap for the plotter streamlines / vectors :type field_cmap: str :param field_sbar_pos_x: The percentage (0 to 1) along the window's horizontal direction to place the bottom left corner of the colorbar. If None it is placed automatically. :type field_sbar_pos_x: float :param field_sbar_pos_y: The percentage (0 to 1) along the window's vertical direction to place the bottom left corner of the colorbar. If None it is placed automatically. :type field_sbar_pos_y: float :param Orbit gif: :param ---------: :param Orbit gif creates a gif that circles around the plotted mesh. The orbital: :param path is always 360 of how many points you have.: :param orbit_gif: Whether to create an orbiting gif :type orbit_gif: bool :param orbit_points: Number of points on the orbiting path :type orbit_points: int :param orbit_step: Timestep between flying to each camera position :type orbit_step: float :param Slices: :param ------: :param This defines the parameters for the two slicing methods: :type This defines the parameters for the two slicing methods: 'slice orthogonal' :param and 'slice'. Note that this only affects sampled source points for vectors or: :param streamlines.: :param normal: tuple(float) or str. Length 3 tuple for the normal vector direction. Can also be specified as a string conventional direction as 'x' for (1,0,0) or '-x' for (-1,0,0) etc. :type normal: str :param origin: The center (x,y,z) coordinate of the plane on which the slice occurs. Note that if method == 'slice orthogonal' then we have that: * x corresponds to x location of the YZ slice * y corresponds to y location of the XZ slice * z corresponds to z location of the XY slice :type origin: tuple .. py:attribute:: title :type: str :value: ' ' .. py:attribute:: title_font_size :type: int :value: 14 .. py:attribute:: n_points :type: int :value: 100 .. py:attribute:: set_seed_1 :type: bool :value: False .. py:attribute:: imageformat :type: str :value: 'png' .. py:attribute:: off_screen :type: bool :value: False .. py:attribute:: window_size :type: tuple :value: (1008, 656) .. py:attribute:: method :type: str :value: 'points' .. py:attribute:: show_axes :type: bool :value: True .. py:attribute:: show_grid :type: bool :value: False .. py:attribute:: scalars_norm :type: str :value: None .. py:attribute:: override_log :type: bool :value: False .. py:attribute:: background_color :type: str :value: 'white' .. py:attribute:: add_volume_opacity_slider :type: bool :value: False .. py:attribute:: widget_type :type: str :value: None .. py:attribute:: camera_centre :type: tuple :value: None .. py:attribute:: focal_point :type: tuple :value: None .. py:attribute:: view_up :type: tuple :value: (0, 0, 1) .. py:attribute:: zoom_factor :type: float :value: None .. py:attribute:: tube_radius :type: float :value: 0.005 .. py:attribute:: show_source :type: bool :value: False .. py:attribute:: surface_streamlines :type: bool :value: False .. py:attribute:: stream_params :type: dict :value: None .. py:attribute:: source_radius :type: float :value: None .. py:attribute:: source_center :type: tuple :value: None .. py:attribute:: stream_variable_radius :type: str :value: None .. py:attribute:: stream_radius_factor :type: float :value: 1 .. py:attribute:: vector_scaling :type: str :value: 'magnitude' .. py:attribute:: vector_factor :type: float :value: 1 .. py:attribute:: vector_max :type: float :value: None .. py:attribute:: show_mesh :type: bool :value: True .. py:attribute:: mesh_type :type: str :value: 'surface' .. py:attribute:: slice_pos :type: tuple :value: (None, None, None) .. py:attribute:: volume_opacity :type: float :value: 0.04 .. py:attribute:: culling :type: str :value: None .. py:attribute:: vertical_sbar :type: bool :value: True .. py:attribute:: cbar_width :type: float :value: 0.06 .. py:attribute:: cbar_height :type: float :value: 0.65 .. py:attribute:: cbar_title_font :type: int :value: 10 .. py:attribute:: cbar_label_font :type: int :value: 8 .. py:attribute:: n_colors :type: int :value: 256 .. py:attribute:: annotation_color :type: str :value: 'black' .. py:attribute:: scalar_sbar_title :type: str :value: None .. py:attribute:: show_mesh_sbar :type: bool :value: True .. py:attribute:: mesh_opacity :type: float :value: 0.2 .. py:attribute:: mesh_cmap :type: str :value: 'bwr' .. py:attribute:: scalar_sbar_pos_x :type: float :value: None .. py:attribute:: scalar_sbar_pos_y :type: float :value: None .. py:attribute:: field_sbar_title :type: str :value: None .. py:attribute:: show_field_sbar :type: bool :value: True .. py:attribute:: field_opacity :type: float :value: 1.0 .. py:attribute:: field_cmap :type: str :value: 'bwr' .. py:attribute:: field_sbar_pos_x :type: float :value: None .. py:attribute:: field_sbar_pos_y :type: float :value: None .. py:attribute:: orbit_gif :type: bool :value: False .. py:attribute:: orbit_points :type: int :value: 35 .. py:attribute:: orbit_step :type: float :value: 2.0 .. py:attribute:: normal :type: str :value: 'x' .. py:attribute:: origin :type: tuple :value: None .. py:attribute:: range_x :type: tuple :value: None .. py:attribute:: range_y :type: tuple :value: None .. py:attribute:: range_z :type: tuple :value: None .. py:attribute:: irange_x :type: tuple :value: None .. py:attribute:: irange_y :type: tuple :value: None .. py:attribute:: irange_z :type: tuple :value: None .. py:method:: update(**kwargs) For updating any key-value pair defined by the self.settings. .. py:class:: Pyvista3DPlot(vector_key, scalar_key, datadir='./data', precision='f', magic='None', ivar=-1, coordinates='cartesian', outputdir=f'./stream_output', settings=Plot3DSettings(), debug=False, irange_x=None, irange_y=None, irange_z=None, range_x=None, range_y=None, range_z=None) Implements 3D plotting routines from pencil var files. It is able to generate streamlines, vectors and isosurfaces. Optionally one can save the output as an image (any Python Pillow compatible image type) or as a gif that orbits (circles) around the plot. Compatible coordinate systems are both cartesian and spherical coordinates. Note that there are multiple ways of sampling source points for the vector field (i.e. streamlines|vectors) and multiple ways of adding the scalars to the plot e.g. volume rendering (only cartesian supported), 3 orthogonal slices or surfaces. Parameter tests --------------- If at least one of the input settings is given as a dictionary parameter test will be enabled automatically. This enables one to input multiple values for settings in a list, and when running streamlines | vectors all these parameter combinations are tried automatically. This is implemented using ``sklearn.ParameterGrid``. * Note that only methods streamlines() and vectors() support parameter tests. * This can be useful for finding good parameters from a large set of options. * Log file is written containing an id and all settings matching to the outputted pictures (id is added to the output image names too). Interface --------- This class defines the following plotting utilities for the user: * scalars --- Adds just the scalar values to the visualization. Scalars can be added as surfaces, volume rendering (only cartesian) and 3 orthogonal slices. This is defined by Plot3DSettings.mesh_type. * streamlines --- Adds streamlines to visualization. In addition scalars are added to mesh in wanted way, i.e. volume rendering can be used in conjunction with streamlines. * vectors --- Adds vectors to visualization. Similarly to streamlines, scalars can be added, e.g. as a volume rendering (only cartesian) * contour --- Adds isosurfaces to visualization. These can be either defined manually or the number of isosurfaces can be set generating uniformly spaced isosurfaces between minimum and maximum value of scalars. * movingIsovalue --- Similar to contour except outputs a "moving" gif visualization that loops from first isosurface to last and backwards. Other utility functions: * writeSettings --- can be used to write the current Plot3DSettings to a json file. * loadSettings --- can be used to load values for Plot3DSettings from a json file. * saveToVTK --- saves the current mesh to a VTK file. This can be used later, e.g. loaded in by PyVista. * updateSettings --- can be used to update one or multiple values of Plot3DSettings without having to reinitialize the whole Pyvista3DPlot object. * preview --- Shows an interactive window that can be panned around showing the camera parameters. This can be used to find good camera parameters. .. rubric:: Examples 1) Very simple usage example Assuming your data is in `./data` directory: >>> from pencil.visu.pv_volume_plotter import Pyvista3DPlot, Plot3DSettings >>> plotter = Pyvista3DPlot(vector_key=['ux','uy','uz'], scalar_key='rho', outputdir='./stream_output', debug=True) Then plot streamlines >>> plotter.streamlines() This should show an interactive plotter window. If not parameter `off_screen` might be true. One way to change this is: >>> plotter.updateSettings(off_screen=False) Now all plots should be done "on screen" that is interactively. When you are plotting surfaces, that is `method='surface'` it might be useful to turn mesh opacity to full 1.0. But then if you have for example streamlines inside the volume these are not visible? This can be fixed by setting parameter `culling='back'` from Plot3DSettings. This means that the front meshes in front of the camera are not rendered at all, only showing the back meshes. How to do this? >>> plotter.updateSettings(culling='back', mesh_opacity=1.0) >>> plotter.streamlines() 2) VOLUME RENDERING SCALARS WITH STREAMLINES OR VECTORS. This assumes your data is in cartesian coordinates. First create the settings object: >>> settings = { 'off_screen': False, # Plotting should be done on screen 'method': 'points', # Ensure streamline source points are taken from the whole volume 'scalars_norm': 'log', # This might be useful for the scalar data 'stream_variable_radius': 'vector magnitude', # Enable stream radius scaling 'stream_radius_factor': 4, # Might be necessary to add multiplicative factor if the radius # doesnt show up (it is so small) 'mesh_type': 'volume', # Enable volume rendering #'volume_opacity': 1/25, # Change this value if rendered volume is very faint } Now that we have settings in dictionary we can initialize the settings object: >>> settings = Plot3DSettings(**settings) >>> plotter = Pyvista3DPlot(vector_key=['ux','uy','uz'], scalar_key='rho', outputdir='./stream_output', settings=settings, debug=True) And finally create the streamlines + volume rendering of scalars >>> plotter.streamlines() Furthermore you could try adding vectors instead of streamlines: >>> plotter.vectors() If this looks bad, you need to tune the vector parameters, example: >>> plotter.updateSettings(vector_scaling='magnitude', vector_factor=1e-2, # Depending on data you need to adjust this smaller or larger # in order to make all vectors smaller or larger vector_max=13, # If the maximal length of vectors is way too large, tone this down ) Now try again: >>> plotter.vectors() 3) ISOSURFACES EXAMPLE: >>> plotter = Pyvista3DPlot(vector_key=['ux','uy','uz'], scalar_key='rho', outputdir='./stream_output', debug=True) >>> plotter.contour(isosurfaces=10) Note, contour might sometimes print out warnings that isosurface has no points, this is most likely due to the isosurface value doesn't correspond to any existing value in the dataset itself. Therefore, it might be more useful to specify manually the isovalues by setting the `values` parameter to some known values. Notes on some missing functionality ----------------------------------- * At the time of development pyvista.add_volume (volume rendering) method supported only pyvista.UniformMesh which made it difficult if not impossible to add volume renderings of data in spherical coordinates. Initialization for the Pyvista3DPlot object. :param vector_key: Keys defining the vector field. Either a single string e.g. 'bb' or a list of 3 strings e.g. ['uu1', 'uu2', 'uu3']. This is read from the var file. :type vector_key: str or list of strings :param scalar_key: Key defining the scalars in the volume. This is read from the var file. :type scalar_key: str :param datadir: Path to the data directory. By default './data' :type datadir: str, optional :param precision: Precision for the pencil.read.var routine. By default 'f'. :type precision: str, optional :param magic: Magic for the pencil.read.var routine. By default 'bb'. :type magic: str, optional :param ivar: Index of the var file read. By default -1. :type ivar: int, optional :param coordinates: Either 'cartesian' or 'spherical'. By default 'cartesian' :type coordinates: str, optional :param outputdir: Path to the directory where the output is saved (images / gif). By default './stream_output' :type outputdir: str, optional :param settings: Plot3DSettings object containing further settings for the plots. See source code for possible arguments, explanations and default values. By default Plot3DSettings(). :type settings: Plot3DSettings, optional :param debug: Enable debug printing. By default False. :type debug: bool, optional .. py:attribute:: datadir .. py:attribute:: outputdir .. py:attribute:: debug :value: False .. py:attribute:: scalar_key .. py:attribute:: vector_key .. py:attribute:: var :value: False .. py:attribute:: grid .. py:attribute:: coordinates :value: 'cartesian' .. py:attribute:: plotter :value: None .. py:attribute:: mesh :value: None .. py:attribute:: src :value: None .. py:attribute:: id_counter :value: 0 .. py:attribute:: field :value: None .. py:attribute:: surface_mesh .. py:method:: writeSettings(filename) Writes current Plot3DSettings to a json file for later use. These can be loaded in by using Pyvista3DPlot.loadSettings Parameter --------- filename: str Name and path where settings are written to in json format. filename SHOULD CONTAIN THE SUFFIX .json .. py:method:: saveToVTK(filename) Saves the current mesh into a .vtk file. File is saved to outputdir and filename should not contain a suffix. .. py:method:: loadSettings(settings) Loads Plot3DSettings to the Pyvista3DPlotter object from the given json file. :param settings: Path to json file containing the Plot3DSettings. This should be written by the method Pyvist3DPlot.writeSettings. :type settings: str .. py:method:: updateSettings(**kwargs) For updating any key-value pair in the dataclass Plot3DSettings. Multiple values can be passed at a time. Example usage: >>> plotter = Pyvista3DPlot() >>> plotter.updateSettings(n_points=1, mesh_cmap='bwr') .. py:method:: streamlines() Add streamlines to plotter. Note that this can be used in conjunction with different source point methods defined in Plot3DSettings.method and also the scalars can be added to the vectors in different ways defined by Plot3DSettings.mesh_type (e.g. just surfaces or volume rendering etc.) streamlines support parameter tests, see docstring of Pyvista3DPlot for explanation. .. py:method:: vectors() Add vectors to plotter. Note that this can be used in conjunction with different source point methods defined in Plot3DSettings.method and also the scalars can be added to the vectors in different ways defined by Plot3DSettings.mesh_type (e.g. just surfaces or volume rendering etc.) streamlines support parameter tests, see docstring of Pyvista3DPlot for explanation. .. py:method:: contour(values=None, isosurfaces=3, filename=f'contour_{int(time.time())}', cmap=None, use_vector_magnitude_as_scalars=False) Similar to movingIsovalue() except an image is saved. Can be used to add or multiple isosurfaces to the image. Opens by default an interactive window in which camera angle can be adjusted, after which an image is saved. values: list of floats Specific values for the isosurfaces. Each isosurface generated corresponds to a value given in this list. If None, automatically generates `isosurfaces` number of isosurfaces between [scalars.min, scalars.max] isosurfaces: int Number of isosurfaces to be generated between scalars minimum and maximum. This applies if parameter `values=None`. Values for the isosurfaces are evenly spaced between the interval. filename: str Output filename, should not contain the image format, it is added automatically based on the given Plot3DSettings.imageformat. cmap: str Matplotlib compatible colormap use_vector_magnitude_as_scalars: bool If true, calculates cartesian norm of the current vector field and uses that as the scalars. .. py:method:: scalars() Plot only the scalar values on to the plotter. .. py:method:: movingIsovalue(values=None, filename=f'moving_isovalue_{time.time()}.gif', isosurfaces=30, show_outline=True, show_mesh_outline=True, cmap=None, use_vector_magnitude_as_scalars=False) Creates a moving isovalue gif that cycles showing the isovalues from first to last and back making a "moving plot". The isovalues itself can be defined, otherwise an isovalue range is created by default of `isosurfaces` amount of isosurfaces between minimum and maximum of scalars. values: list of floats Specific values for the isosurfaces. Each isosurface generated corresponds to a value given in this list. If None, automatically generates `isosurfaces` number of isosurfaces between [scalars.min, scalars.max] filename: str Output filename for the gif. Defaults to 'moving_isovalue_.gif' isosurfaces: int Number of isosurfaces to be generated between scalars minimum and maximum. This applies if parameter `values=None`. Values for the isosurfaces are evenly spaced between the interval. show_outline: bool Shows an outline box in which the mesh is contained in. show_mesh_outline: bool TODO! cmap: str Matplotlib compatible colormap use_vector_magnitude_as_scalars: bool If true, calculates cartesian norm of the current vector field and uses that as the scalars. .. py:method:: preview() !TODO!