### DataSetBuilder Start and Stop Methods (Python) Source: https://www.paraview.org/paraview-docs/v5.11.0/python/_modules/paraview/web/dataset_builder Provides the start and stop methods for a DataSetBuilder class in Python. The 'start' method likely initializes the view, while 'stop' handles data processing and optional compression. Dependencies include 'os', 'gzip', and 'shutil'. ```python [docs] def start(self): DataSetBuilder.start(self, self.view) [docs] def stop(self, compress=True): if not self.dataHandler.can_write: return # Push metadata self.dataHandler.addSection("FloatImage", self.floatImage) # Write metadata DataSetBuilder.stop(self) if compress: for root, dirs, files in os.walk(self.dataHandler.getBasePath()): print("Compress", root) for name in files: if ".array" in name and ".gz" not in name: with open(os.path.join(root, name), "rb") as f_in: with gzip.open( os.path.join(root, name + ".gz"), "wb" ) as f_out: shutil.copyfileobj(f_in, f_out) os.remove(os.path.join(root, name)) ``` -------------------------------- ### Simplified Pipeline Creation and Rendering in ParaView Python Source: https://www.paraview.org/paraview-docs/v5.11.0/python/quick-start Demonstrates a more concise way to create and render a pipeline using the paraview.simple module by relying on the active object. It shows how to create a Cone, set its properties using SetProperties, apply a Shrink filter, show the result, and render the view without explicitly assigning objects to variables. ```python >>> from paraview.simple import * >>> Cone() >>> SetProperties(Resolution=32) >>> Shrink() >>> Show() >>> Render() ``` -------------------------------- ### ParaView Simple Module Usage Example Source: https://www.paraview.org/paraview-docs/v5.11.0/python/_modules/paraview/simple Demonstrates how to use the paraview.simple module to create a sphere, apply a shrink filter, show the result, and render the scene. This example requires the paraview library to be installed. ```python from paraview.simple import * # Create a new sphere proxy on the active connection and register it # in the sources group. sphere = Sphere(ThetaResolution=16, PhiResolution=32) # Apply a shrink filter shrink = Shrink(sphere) # Turn the visibility of the shrink object on. Show(shrink) # Render the scene Render() ``` -------------------------------- ### Accessing Properties and Data Information Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.FiniteElementFieldDistributor This example shows how to access properties and data information for a ParaView proxy, such as the FiniteElementFieldDistributor. You can list all available properties or get specific property values. ```python from paraview.simple import * # Assuming 'proxy_object' is an instance of a ParaView proxy like FiniteElementFieldDistributor # proxy_object = FiniteElementFieldDistributor(...) # List all properties properties = proxy_object.ListProperties() print("Available properties:", properties) # Get a specific property value (e.g., 'Input') input_property_value = proxy_object.GetPropertyValue('Input') print("Input property value:", input_property_value) # Get a property object for more detailed access input_property_object = proxy_object.GetProperty('Input') print("Input property object:", input_property_object) ``` -------------------------------- ### Create and Configure a Cone Source in ParaView Python Source: https://www.paraview.org/paraview-docs/v5.11.0/python/quick-start Instantiates a Cone source object and demonstrates how to set its properties, such as Resolution and Center, both during initialization and after creation. It also shows how to retrieve and modify vector properties like Center. ```python >>> cone = Cone() >>> help(cone) >>> cone.Resolution 6 >>> cone.Resolution = 32 >>> cone = Cone(Resolution=32) >>> cone.Center [0.0, 0.0, 0.0] >>> cone.Center = [1, 2, 3] >>> cone.Center[0:2] = [2, 4] >>> cone.Center [2.0, 4.0, 3.0] ``` -------------------------------- ### Example: Running ParaView Tracing Source: https://www.paraview.org/paraview-docs/v5.11.0/python/_modules/paraview/smtrace Demonstrates a basic usage of the ParaView tracing API. It starts tracing, creates a sphere and a plot, shows them, and then stops tracing to print the output. ```python import paraview.simple as simple from paraview.trace import Trace def start_trace(preamble=None): return simple.vtkSMTrace.StartTrace(preamble) def stop_trace(): return simple.vtkSMTrace.StopTrace() def get_current_trace_output(raw=False): return str(Trace.Output) if not raw else Trace.Output.raw_data() def get_current_trace_output_and_reset(raw=False): output = get_current_trace_output(raw) reset_trace_output() return output def reset_trace_output(): Trace.Output.reset() if __name__ == "__main__": print ("Running test") start_trace() s = simple.Sphere() c = simple.PlotOverLine() simple.Show() print ("***** TRACE RESULT *****") print (stop_trace()) ``` -------------------------------- ### Startup Plugin Loader: ParaViewWebStartupPluginLoader Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.web.protocols Handles the loading of plugins during ParaView Web startup. It can be configured with a list of plugins and a path separator. ```python _class _paraview.web.protocols.ParaViewWebStartupPluginLoader(_plugins =None_, _pathSeparator =':'_, _** kwargs_)[source]¶ Bases: `paraview.web.protocols.ParaViewWebProtocol` loaded _ = False_¶ ``` -------------------------------- ### Proxy Initialization and Management Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.PythonCalculator Methods for initializing a proxy from an existing one, listing all properties, and managing proxy lifecycle. ```APIDOC ## POST /proxy/initialize ### Description Initializes the proxy with another proxy object. Optionally updates the server object and registers the proxy. ### Method POST ### Endpoint `/proxy/initialize` ### Parameters #### Request Body - **aProxy** (object) - Required - The proxy object to initialize from. - **update** (boolean) - Optional - Whether to update the server object. Defaults to true. ### Response #### Success Response (200) - **message** (string) - Confirmation message of successful initialization. #### Response Example ```json { "message": "Proxy initialized successfully." } ``` ## GET /proxy/properties ### Description Returns a list of all property names available on this proxy. ### Method GET ### Endpoint `/proxy/properties` ### Response #### Success Response (200) - **property_names** (array) - A list of strings, where each string is a property name. #### Response Example ```json { "property_names": ["Property1", "Property2", "ExampleProperty"] } ``` ## DELETE /proxy ### Description Destructor for the proxy. Cleans up observers and removes the proxy from the internal registry. ### Method DELETE ### Endpoint `/proxy` ### Response #### Success Response (200) - **message** (string) - Confirmation message of successful cleanup. #### Response Example ```json { "message": "Proxy cleaned up successfully." } ``` ``` -------------------------------- ### Import NumPy and Handle ImportError in Python Selector Source: https://www.paraview.org/paraview-docs/v5.11.0/python/_modules/paraview/detail/python_selector This Python code snippet imports the NumPy library, which is essential for the functionality of the python_selector module. It includes error handling to raise a RuntimeError if NumPy is not found, guiding the user to install it. ```python from __future__ import absolute_import, print_function try: import numpy as np except ImportError: raise RuntimeError ("'numpy' module is not found. numpy is needed for " "this functionality to work. Please install numpy and try again.") import re import vtkmodules.numpy_interface.dataset_adapter as dsa import vtkmodules.numpy_interface.algorithms as algos from vtkmodules.vtkCommonDataModel import vtkDataObject from vtkmodules.util import vtkConstants from . import calculator ``` -------------------------------- ### Get All Render Views (Python) Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.servermanager Retrieves a set containing all active render views within the ParaView application. This is useful when dealing with multi-view setups. Dependencies: None. Input: Optional Connection object. Output: Set of Render View objects. ```python paraview.servermanager.GetRenderViews(_connection =None_) ``` -------------------------------- ### Demonstration Functions Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.servermanager Utility functions to demonstrate various ParaView functionalities. ```APIDOC ## demo1 ### Description This simple demonstration creates a sphere, renders it and delivers it to the client using Fetch. It returns a tuple of (data, render view). ### Method GET (Conceptual) ### Endpoint N/A (Function) ### Response #### Success Response (200) - **data** (any) - The fetched data. - **render_view** (RenderViewProxy) - The render view created. ## demo2 ### Description This method demonstrates the use of a reader, representation and view. It also demonstrates how meta-data can be obtained using proxies. Make sure to pass the full path to an exodus file. Also note that certain parameters are hard-coded for disk_out_ref.ex2 which can be found in ParaViewData. This method returns the render view. ### Method GET (Conceptual) ### Endpoint N/A (Function) ### Parameters #### Query Parameters - **fname** (string) - Optional - The full path to an exodus file (default: '/Users/berk/Work/ParaViewData/Data/disk_out_ref.ex2'). ### Response #### Success Response (200) - **render_view** (RenderViewProxy) - The render view created. ## demo3 ### Description This method demonstrates the use of servermanager with numpy as well as pylab for plotting. It creates an artificial data source, probes it with a line, delivers the result to the client using Fetch and plots it using pylab. This demo requires numpy and pylab installed. It returns a tuple of (data, render view). ### Method GET (Conceptual) ### Endpoint N/A (Function) ### Response #### Success Response (200) - **data** (any) - The fetched data. - **render_view** (RenderViewProxy) - The render view created. ## demo4 ### Description This method demonstrates the user of AnimateReader for creating animations. ### Method GET (Conceptual) ### Endpoint N/A (Function) ### Parameters #### Query Parameters - **fname** (string) - Optional - The path to the file to animate (default: '/Users/berk/Work/ParaViewData/Data/can.ex2'). ## demo5 ### Description Simple sphere animation. ### Method GET (Conceptual) ### Endpoint N/A (Function) ## updateModules ### Description Deprecated. Not needed since 5.10. ### Method POST (Conceptual) ### Endpoint N/A (Function) ### Parameters #### Query Parameters - **m** (any) - Optional - Module identifier. ``` -------------------------------- ### LiveProgrammableSource Initialization and Property Setting (Python) Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.LiveProgrammableSource Demonstrates how to initialize a LiveProgrammableSource and set its properties using Python. This includes setting the script for data generation and defining the output dataset type. ```python from paraview.simple import LiveProgrammableSource # Create a LiveProgrammableSource instance my_source = LiveProgrammableSource() # Set the script for data generation my_source.Script = """ def execute(): # Your data generation logic here pass """ # Set the output dataset type my_source.OutputDataSetType = "vtkUnstructuredGrid" # Optionally, set other properties like TimestepValues or PythonPath # my_source.TimestepValues = [0.0, 1.0, 2.0] # my_source.PythonPath = "/path/to/your/scripts" print("LiveProgrammableSource created and configured.") ``` -------------------------------- ### Get ParaView Data Information in Python Source: https://www.paraview.org/paraview-docs/v5.11.0/python/_modules/paraview/web/protocols Python function to retrieve detailed information about ParaView data, including bounds, number of points and cells, data type, and memory size. This function requires the representation to be created first. It also starts gathering information about point data arrays. ```python def getDataInformation(self, proxy): # The stuff in here works, but only after you have created the # representation. dataInfo = proxy.GetDataInformation() # Get some basic statistics about the data info = { "bounds": dataInfo.DataInformation.GetBounds(), "points": dataInfo.DataInformation.GetNumberOfPoints(), "cells": dataInfo.DataInformation.GetNumberOfCells(), "type": dataInfo.DataInformation.GetPrettyDataTypeString(), "memory": dataInfo.DataInformation.GetMemorySize(), } arrayData = [] # Get information about point data arrays pdInfo = proxy.GetPointDataInformation() ``` -------------------------------- ### Proxy Initialization and Management Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.TemporalShiftScale Methods for initializing a proxy from another, managing observers, and handling proxy registration. ```APIDOC ## InitializeFromProxy ### Description Initializes the current proxy using another proxy's configuration. It can optionally update the server object and register the proxy. ### Method Various (internal calls) ### Endpoint N/A (Object Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **aProxy** (object) - The proxy object to initialize from. - **update** (boolean) - Optional. Whether to update the server object (default is True). ### Request Example ```python proxy.InitializeFromProxy(another_proxy) ``` ### Response #### Success Response (200) Indicates successful initialization. #### Response Example ```json { "status": "initialized" } ``` ## __del__ ### Description Destructor method. Cleans up observers and removes the proxy from the internal registry. ### Method Destructor ### Endpoint N/A (Object Method) ### Parameters None ### Request Example ```python # Called automatically when the proxy object is garbage collected del proxy ``` ### Response #### Success Response (200) Indicates successful cleanup. #### Response Example ```json { "status": "cleaned_up" } ``` ``` -------------------------------- ### Synthetic Data, Probing, Fetching, and Plotting with NumPy/Pylab Source: https://www.paraview.org/paraview-docs/v5.11.0/python/_modules/paraview/servermanager Demonstrates generating synthetic data, probing it with a line, fetching the results to the client, and plotting the data using Pylab. This example requires NumPy and Pylab to be installed. It handles version compatibility for data source creation. Returns a tuple of fetched data and the render view. Imports `numpy_support` from `vtkmodules.util` and `pylab`. ```python def demo3(): """This method demonstrates the use of servermanager with numpy as well as pylab for plotting. It creates an artificial data sources, probes it with a line, delivers the result to the client using Fetch and plots it using pylab. This demo requires numpy and pylab installed. It returns a tuple of (data, render view).""" from vtkmodules.util import numpy_support import pylab if not ActiveConnection: Connect() # Create a synthetic data source if paraview.compatibility.GetVersion() <= 3.4: ``` -------------------------------- ### Get Property Information - Python Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.XMLStructuredGridWriter Retrieves property information from a proxy object. Includes methods to get a property by name, get its value, and list all available properties. Assumes the existence of a proxy object. ```python proxy.GetProperty('PropertyName') proxy.GetPropertyValue('PropertyName') proxy.ListProperties() ``` -------------------------------- ### Proxy Initialization and Lifecycle Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.NetCDFReader Methods related to proxy creation, initialization, and destruction. ```APIDOC ## POST /proxy ### Description Initializes a new proxy. Can be used to create a new server manager proxy with optional initial properties. ### Method POST ### Endpoint `/proxy` ### Parameters #### Request Body - **proxy_type** (string) - Required - The type of proxy to create (e.g., 'reader', 'filter'). - **initial_properties** (object) - Optional - A key-value map of initial property settings. - **registration_group** (string) - Optional - The group name for registering the proxy. - **registration_name** (string) - Optional - The name for registering the proxy. ### Request Example ```json { "proxy_type": "GeometryRepresentation", "initial_properties": { "ColorArray": "Points[Normals]", "Opacity": 0.8 }, "registration_name": "MyCustomRepresentation" } ``` ### Response #### Success Response (201) - **proxy_id** (string) - The unique identifier of the newly created proxy. - **message** (string) - Confirmation message. #### Response Example ```json { "proxy_id": "proxy_12345", "message": "Proxy created and registered successfully." } ``` ## POST /proxy/{proxy_id}/initialize ### Description Initializes an existing proxy object with another proxy and optionally updates the server object. ### Method POST ### Endpoint `/proxy/{proxy_id}/initialize` ### Parameters #### Path Parameters - **proxy_id** (string) - Required - The unique identifier of the proxy to initialize. #### Request Body - **source_proxy_id** (string) - Required - The ID of the proxy to copy properties from. - **update_server** (boolean) - Optional - Whether to update the server object. Defaults to true. ### Request Example ```json { "source_proxy_id": "proxy_abcde", "update_server": false } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Proxy initialized successfully." } ``` ## DELETE /proxy/{proxy_id} ### Description Destroys a proxy, cleaning up observers and removing it from the registry. ### Method DELETE ### Endpoint `/proxy/{proxy_id}` ### Parameters #### Path Parameters - **proxy_id** (string) - Required - The unique identifier of the proxy to destroy. ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Proxy destroyed successfully." } ``` ``` -------------------------------- ### Python: Load and Start ParaView Flow Web Application Source: https://www.paraview.org/paraview-docs/v5.11.0/python/_modules/paraview/apps/flow Loads and starts the ParaView Flow web application. It checks if the application is available in the build package and raises a RuntimeError if not. It then starts the server with a description and the application module. ```python from . import _internals as internals appname = "flow" [docs]def main(): app = internals.load_webapp(appname) if not app: raise RuntimeError("This application is not available in your build package.") internals.start_server(appname = appname, description = "ParaView Flow - ParaViewWeb viewer for ParFlow data", module = app, protocol = app._Server) [docs]def is_supported(): if internals.find_webapp(appname): return True return False if __name__ == "__main__": main() ``` -------------------------------- ### Load ParaView Simple Module (Python) Source: https://www.paraview.org/paraview-docs/v5.11.0/python/quick-start This snippet demonstrates how to load the 'simple' module from the paraview library in Python. This is the primary method for interacting with the ParaView Server Manager. Ensure ParaView's Python modules are in your PYTHONPATH. ```python >>> from paraview.simple import * ``` -------------------------------- ### ParaView Demonstration Functions Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.servermanager Includes several demonstration functions that showcase different aspects of the ParaView server manager. These demos illustrate creating data, rendering, fetching data to the client, using readers and representations, animating, and integrating with libraries like NumPy and Matplotlib. ```python # Creates a sphere, renders it, and fetches it to the client. demo1() # Demonstrates reader, representation, view, and metadata retrieval using an exodus file. demo2(_fname ='/Users/berk/Work/ParaViewData/Data/disk_out_ref.ex2'_) # Demonstrates server manager with numpy and pylab for plotting artificial data. demo3() # Demonstrates AnimateReader for creating animations with an exodus file. demo4(_fname ='/Users/berk/Work/ParaViewData/Data/can.ex2'_) # Simple sphere animation. demo5() ``` -------------------------------- ### Example: Data Loading and Processing Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.HyperTreeGridGeometryFilter Illustrative examples of using ParaView Python functions for common data operations. ```APIDOC ## GET /api/paraview/simple/CSVReader ### Description Reads data from a CSV file. ### Method GET ### Endpoint `/api/paraview/simple/CSVReader` ### Parameters #### Query Parameters * **FileName** (string) - Required - The path to the CSV file. * **HaveHeaders** (boolean) - Optional - Specifies if the CSV file has a header row. ### Request Example ```json { "FileName": "/path/to/your/data.csv", "HaveHeaders": true } ``` ### Response #### Success Response (200) - **dataset** (object) - The loaded dataset object. #### Response Example ```json { "dataset": { "//": "Representation of the loaded dataset" } } ``` ## POST /api/paraview/simple/Calculator ### Description Applies a mathematical expression to data arrays to create new arrays. ### Method POST ### Endpoint `/api/paraview/simple/Calculator` ### Parameters #### Request Body - **input** (object) - Required - The input dataset. - **Function** (string) - Required - The mathematical expression to evaluate (e.g., 'Temperature + 10'). - **ResultArrayName** (string) - Optional - The name for the new array. ### Request Example ```json { "input": { "//": "Reference to an existing dataset" }, "Function": "pressure * 0.5", "ResultArrayName": "NewPressure" } ``` ### Response #### Success Response (200) - **output** (object) - The dataset with the new array added. #### Response Example ```json { "output": { "//": "Representation of the dataset with the added array" } } ``` ``` -------------------------------- ### Render Pipeline Output in ParaView Python Source: https://www.paraview.org/paraview-docs/v5.11.0/python/quick-start Renders the output of a data pipeline in ParaView. This involves showing the data using the Show() function and then rendering the scene using the Render() function. It illustrates the basic steps required to visualize the results of created sources and filters. ```python >>> Show(shrinkFilter) >>> Render() ``` -------------------------------- ### Start ParaView Web Server Source: https://www.paraview.org/paraview-docs/v5.11.0/python/_modules/paraview/apps/_internals Initializes and starts the web server for a ParaView web application. It uses `argparse` to handle command-line arguments, integrating arguments from the module's server and protocol configurations. The server is then started with the parsed options. ```python def start_server(appname, description, module, protocol): import argparse # Create argument parser parser = argparse.ArgumentParser(description=description) # Add arguments module.server.add_arguments(parser) protocol.add_arguments(parser) args = parser.parse_args(get_commandline_args(appname)) protocol.configure(args) # Start server module.server.start_webserver(options=args, protocol=protocol) ``` -------------------------------- ### ParaView Simple Module - Example Functions Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.JSONImageWriter Examples of common functions available in the `paraview.simple` module for data manipulation and visualization. ```APIDOC ## `paraview.simple` Module - Common Functions ### Description The `paraview.simple` module provides convenient access to frequently used readers, sources, writers, filters, and animation cues within ParaView. ### Examples #### Readers * **`paraview.simple.AMReXBoxLibGridReader(FileName)`**: Reads data from an AMReX BoxLib grid file. * **`paraview.simple.CSVReader(FileName)`**: Reads data from a CSV file. #### Sources * **`paraview.simple.Cone()`**: Creates a cone geometric source. * **`paraview.simple.Cylinder(Resolution=32)`**: Creates a cylinder geometric source with a specified resolution. #### Filters * **`paraview.simple.Clip(Input=dataset, ClipType='Plane')`**: Clips a dataset using a specified clip type. * **`paraview.simple.Contour(Input=dataset, ContoursValue=[value])`**: Generates contour surfaces for a dataset at specified values. #### Writers * **`paraview.simple.CSVWriter(FileName, Input=dataset)`**: Writes dataset to a CSV file. * **`paraview.simple.CGNSWriter(FileName, Input=dataset)`**: Writes dataset to a CGNS file. #### Animation * **`paraview.simple.AnimationScene()`**: Creates an animation scene object. * **`paraview.simple.CameraAnimationCue(AnimationScene=scene)`**: Creates a camera animation cue. ``` -------------------------------- ### Proxy Initialization and Registration Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.XMLPRectilinearGridWriter Methods for initializing a proxy from another proxy and managing its registration. ```APIDOC ## InitializeFromProxy ### Description Initializes the current proxy object from another existing proxy, with an option to update the server object and register it. ### Method `InitializeFromProxy(self, aProxy, update=True)` ### Parameters #### Path Parameters - **aProxy** (object) - Required - The proxy object to initialize from. - **update** (boolean) - Optional - Whether to update the server object. Defaults to True. ## __init__ (Constructor) ### Description Default constructor for a proxy object. Can be used to initialize properties via keyword arguments. Optional `registrationGroup` and `registrationName` can be provided to automatically register the proxy. ### Method `__init__(self, **args)` ### Parameters #### Query Parameters - **args** (dict) - Optional - Keyword arguments for property initialization, registration group, and registration name. ``` -------------------------------- ### Proxy Initialization and Registration Source: https://www.paraview.org/paraview-docs/v5.11.0/python/paraview.simple.XMLPImageDataWriter Methods for initializing a proxy from another proxy and for managing proxy registration. ```APIDOC ## POST /proxy/initialize ### Description Initializes the current proxy from another provided proxy. Optionally updates the server object and registers the proxy. ### Method POST ### Endpoint `/proxy/initialize` ### Parameters #### Request Body - **sourceProxy** (object) - Required - The proxy object to initialize from. - **update** (boolean) - Optional - Whether to update the server object (defaults to true). ### Request Example ```json { "sourceProxy": { "id": "123", "name": "MySource" }, "update": true } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Proxy initialized successfully." } ``` ## POST /proxy/register ### Description Registers the proxy with the proxy manager using the provided registration group and name. ### Method POST ### Endpoint `/proxy/register` ### Parameters #### Request Body - **registrationGroup** (string) - Optional - The group to register the proxy under. - **registrationName** (string) - Optional - The name to register the proxy with. ### Request Example ```json { "registrationGroup": "Readers", "registrationName": "MyCustomReader" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Proxy registered successfully." } ``` ```