A visualizing toolkit for PyElastica developed as part of the work undetaken in GSoC 2022. Still a continuing work in progress so features will continue to be added and compatability cannot be guaranteed.
PyElasticaVisualizer uses Poetry for its dependency management, like PyElastica. With potetry installed, to run your visualization script, simply use poetry run python your_script.py.
The visualizer tool is designed to work with data produced by PyElastica simulations through its callback functionality. For the quickest way to get a bare-bones visualization of a simulation working:
-
Collect simulation diagnostics using
VisualizerDictCallBackfromutils.pypostprocessing_dict = {"object1": defaultdict(list), "object2": defaultdict(list), ... } pyelastica_sim.collect_diagnostics(object1).using( VisualizerDictCallBack, step_skip=step_skip, callback_params=postprocessing_dict["object1"] ) pyelastica_sim.collect_diagnostics(object2).using( VisualizerDictCallBack, step_skip=step_skip, callback_params=postprocessing_dict["object2"] ) ...
Note the
VisualizerDictCallBackmust be attached to each object in the system, so it can be cumbersome when there are many objects in a system.The postprocessing dict must also be specified as done above.
-
Use the
generate_visualization_dictfunction fromutils.pyto reformat postprocessing dictionary into the correct format to pass to the Visualizervisualization_dict = generate_visualization_dict(postprocessing_dict, grouping_parameters=None)
The purpose of the visualization dicitionary is to have a defined standard for passing simulation data and visualization parameters to the visualizer.
grouping_parametersis a dictionary passed to the function that can be used to specify groups of objects in the simulation and define paramters for this group to be used when visualizing these objects eg. color, level of detail etc. The format is likely to change a lot as more features are added to visualizer. -
Initialise and run the visualizer. There are two possible visualizers that can be used at the current moment the
Visualizerclass invisualizer.pyandVisualizerGUIclass inqt_visualizer.py. TheVisualizerclass is only the Vispy canvas, whileVisualizerGUIis the Vispy canvas emedded into a GUI made with QT. TheVisualizerGUIembedded canvas has all the features of the standalone visualization canvas; the only reason for the existence of the baseVisualizeris that it is better for saving the visualization as a video file, however, this is planned to be implemented in theVisualizerGUIclass shortly.Using the
Visualizerclass:Visualizer = Visualizer(visualization_dict) Visualizer.add_axis('x') # Example of adding an axis to the scene Visualizer.add_axis('z') Visualizer.turntable_camera() # Sets a camera type Visualizer.run()
Using the
VisualizerGUIclass:canvas = CanvasWrapper(visualization_dict) canvas.add_axis("z") canvas.add_axis("x") canvas.turntable_camera() Visualizer = VisualizerGUI(visualization_dict, canvas) Visualizer.run()
This is an ongoing project that is intended to be developed after GSoC, and there will be new features and improvements in the future.
There are a several PyElastica example simulations in the examples/ directory which have been modified to be visualized, and can be used as examples.