def initialize(self): dir = self.paraview_scripts_directory tensor_glyph_path = dir + '/tensorGlyph.xml' tensor_glyph_custom_path = dir + '/tensorGlyphWithCustomSource.xml' assert os.path.isfile(tensor_glyph_path), \ 'File does not exist: ' + tensor_glyph_path assert os.path.isfile(tensor_glyph_custom_path), \ 'File does not exist: ' + tensor_glyph_custom_path if not servermanager.ActiveConnection: exit('pvpython not supported. Use ParaView\'s Python shell.') # Detect ParaView version and load tensor plugins. try: from paraview import simple # This is ParaView 3.6 or higher. version = 6 simple.LoadPlugin(tensor_glyph_path) simple.LoadPlugin(tensor_glyph_custom_path) except ImportError: # This must be ParaView 3.4. simple = None version = 4 load_xml_plugin(tensor_glyph_path) load_xml_plugin(tensor_glyph_custom_path) # The RenderView is needed by clear() as well as by build(). if len(servermanager.GetRenderViews()) > 0: rv = servermanager.GetRenderViews()[0] else: rv = servermanager.CreateRenderView() # Disable polygon offset (z-fighting prevention), otherwise # wireframe is shifted. # http://www.mail-archive.com/[email protected]/msg08812.html from libvtkRenderingPython import vtkMapper vtkMapper.SetResolveCoincidentTopologyToOff() self.version = version self.rv = rv self.simple = simple
def __init__(self, plugins=None, pathSeparator=':'): super(ParaViewWebStartupPluginLoader, self).__init__() if not ParaViewWebStartupPluginLoader.loaded and plugins: ParaViewWebStartupPluginLoader.loaded = True for path in plugins.split(pathSeparator): simple.LoadPlugin(path, ns=globals())
def main(): import sys # to get command line args import argparse # to parse options for us and print a nice help message argv = sys.argv if __file__ in argv: argv = argv[argv.index(__file__) + 1:] # get all args after __file__ usage_text = "Run ParaView in background mode with this script:" usage_text += " pvpython " + __file__ + " [options]" parser = argparse.ArgumentParser(description=usage_text) parser.add_argument("-i", "--input", dest="input", metavar='FILE', required=True, help="Input path contained in a text file.") parser.add_argument("-p", "--plugin", dest="plugin", metavar='FILE', required=True, help="Path to FA-plugin (libFacetAnalyser.so).") parser.add_argument("-o", "--output", dest="output", metavar='FILE', required=True, help="Output name to export X3D") args = parser.parse_args(argv) if not argv: parser.print_help() return if not args.input: print('Need an input file') parser.print_help() sys.exit(1) if not args.plugin: print('Need a plugin file') parser.print_help() sys.exit(1) if not args.output: print('Need an output file') parser.print_help() sys.exit(1) pvs.LoadPlugin(args.plugin, remote='False') ## read pvsm pvs.LoadState(args.input) rv = pvs.GetRenderView() exporters = pvs.servermanager.createModule("exporters") # dir(exporters) # lists export modules: CSVExporter, CinemaExporter, GL2PSContextViewExporterBase, GL2PSContextViewExporterEPS, GL2PSContextViewExporterPDF, GL2PSContextViewExporterPS, GL2PSContextViewExporterSVG, GL2PSExporterBase, GL2PSRenderViewExporterBase, GL2PSRenderViewExporterEPS, GL2PSRenderViewExporterPDF, GL2PSRenderViewExporterPS, GL2PSRenderViewExporterSVG, POVExporter, VRMLExporter, WebGLExporter, X3DExporter, X3DExporterBinary exporter = exporters.X3DExporter(FileName=args.output) exporter.SetView(rv) exporter.Write() ## output for ctest for regex-check because script itself fails with: ## Inconsistency detected by ld.so: dl-close.c: _dl_close: Assertion `map->l_init_called' failed! ## this happens even without qt-at-spi: http://www.cfd-online.com/Forums/openfoam-paraview/128851-pvpython-ubuntu-deb-package.html if os.path.isfile(args.output): print("Export succeded") else: print("Export failed")
import os from paraview import simple # ----------------------------------------------------------------------------- MODULE_PATH = os.path.dirname(os.path.abspath(__file__)) PLUGINS = [ 'parflow.py' ] FULL_PATHS = [ '/Applications/ParaView-5.6.0-1626-g52acf2f741.app/Contents/Plugins/ParFlow.so', ] # ----------------------------------------------------------------------------- # Load the plugins # ----------------------------------------------------------------------------- for plugin in PLUGINS: simple.LoadPlugin(os.path.join(MODULE_PATH, plugin)) for plugin in FULL_PATHS: simple.LoadPlugin(plugin)
# attempt using ParaView-internal functions: # WaveformDataReader = pv._create_func("WaveformDataReader", pvserver.sources) # WaveformToVolume = pv._create_func("WaveformToVolume", pvserver.filters) logger.info("Loading ParaView plugins...") plugins_dir = files("gwpv.paraview_plugins") load_plugins = [ "WaveformDataReader.py", "WaveformToVolume.py", "TrajectoryDataReader.py", "FollowTrajectory.py", "TrajectoryTail.py", # 'SwshGrid.py' ] for plugin in load_plugins: with as_file(plugins_dir / plugin) as plugin_path: pv.LoadPlugin(str(plugin_path), remote=False, ns=globals()) logger.info("ParaView plugins loaded.") def render_frames( scene, frames_dir=None, frame_window=None, render_missing_frames=False, save_state_to_file=None, no_render=False, show_preview=False, show_progress=False, job_id=None, ): # Validate scene
import paraview.simple as pvs if not 'NetCDFLFRicReader' in dir(pvs): # Load the LFRic reader plugin if it has not been loaded already. It may be # necessary to provide the full path to the library, depending on the installation. # As of ParaView v5.7, the library is named "netCDFLFRicReader.so". # Set remote=True if you connect ParaView with a separate server. pluginPath = '' pvs.LoadPlugin(pluginPath + 'libnetCDFLFRicReader.so', remote=False) # Create a new data source with the LFRic output data, load the pressure field, # and use Cartesian coordinates rather than lon-lat-rad filePath = '' data = pvs.NetCDFLFRicReader(FileName=filePath + 'lfric_output.nc') data.CellArrayStatus = ['pressure'] data.UseCartesiancoordinates = 1 # Add a clip filter to the pipeline and set plane orientation clip = pvs.Clip(Input=data) clip.ClipType = 'Plane' clip.ClipType.Normal = [0.0, 0.0, 1.0] # Set up a new render view for displaying the grid and data renderView = pvs.CreateView('RenderView') renderView.ViewSize = [1600, 800] renderView.CameraPosition = [-43.0, 39.0, 32.0] renderView.CameraViewUp = [0.76, 0.44, 0.49] # Define a colour look-up table using (data value, r, g, b) tuples # Use value range from first timestep lut = pvs.GetColorTransferFunction('pressure')
tempDir = SMPythonTesting.TempDir stateDir = SMPythonTesting.SMStatesDir sphere = smp.Sphere() f = smp.ProgrammableFilter(sphere) script = ''' assert 1+1 == 2 ''' assert testScript(f, script) script = ''' assert foo == 'bar' ''' f.SetPropertyWithName('Parameters', ['foo', '"bar"']) assert testScript(f, script) smp.LoadPlugin(os.path.join(stateDir, 'ProgrammableFilterPropertiesTest.xml')) f = smp.ProgrammableFilterPropertiesTest(sphere) assert f.DoubleTest == 1.23 assert f.IntTest == 123 assert f.StringTest == 'string value' assert testScript(f, f.Script)
import paraview.simple as pv import glob import numpy as np pv.LoadPlugin("/Users/jjm390/libGhostKit.dylib") filelist = glob.glob("/Volumes/Data 1/PhD Data/MHD/LFMRCM/ToProcess/*.hdf") filelist = sorted(filelist) currentfile = pv.vtkLFMReader(FileNames=filelist[0]) currentfile.GridScaleFactor = 'Earth Radius: 6.5e8 cm' currentfile.CellArrayStatus = ['Magnetic Field Vector'] calc = pv.Calculator() calc.Input = currentfile calc.Function = 'Magnetic Field Vector * 1e5' calc.ResultArrayName = 'B' DataRepresentation1 = pv.Show() DataRepresentation1.SelectionPointFieldDataArrayName = 'Magnetic Field Vector' segment = 16 end = None outdir = "./outdata3/" for file in filelist[segment:]: print("Number: {0}".format(segment)) print("Loading File:", file) fileparts = str.split(file, '/') nameparts = str.split(fileparts[-1], '.')