Source-linked AI summary

Mayavi: a package for 3D visualization of scientific data

Prabhu Ramachandran, Gaël Varoquaux

arXiv:1010.4891v1cs.SE

TL;DR

Mayavi addresses the need for interactive, workflow-compatible 3D scientific visualization in Python. It combines an end-user application, scripting interfaces, reusable objects, embeddable widgets, and plugins. The resulting package supports interactive exploration, automated scripting, domain-specific applications, and web-based visualization.

  • Problem

    Scientific users need interactive 3D visualization that fits computational workflows, while complex datasets benefit from scripting and interactive exploration.

  • Method

    Mayavi combines an interactive application, MATLAB-like and feature-rich Python APIs, embeddable widgets, and plugins built around reusable visualization components.

  • Results

    Mayavi supports interactive and scripted visualization, embedding in domain-specific applications, automated weather-data workflows, and browser-based rendering.

  • Takeaways & Limitations

    Mayavi provides a Python-centered 3D visualization environment spanning end-user exploration, programmatic use, application embedding, and off-screen web rendering.

Abstract

from arXiv · show

Mayavi is an open-source, general-purpose, 3D scientific visualization package. It seeks to provide easy and interactive tools for data visualization that fit with the scientific user's workflow. For this purpose, Mayavi provides several entry points: a full-blown interactive application; a Python library with both a MATLAB-like interface focused on easy scripting and a feature-rich object hierarchy; widgets associated with these objects for assembling in a domain-specific application, and plugins that work with a general purpose application-building framework. In this article, we present an overview of the various features of Mayavi, we then provide insight on the design and engineering decisions made in implementing Mayavi, and finally discuss a few novel applications.

What is Mayavi?

Mayavi is a reusable, general-purpose 3D visualization environment that integrates interactive applications, scripting, widgets, and plugins into Python-based scientific workflows.

  • A unique integration with a scientific workflow: Mayavi combines a visualization library with an application, widgets, dialogs, and plugins for different parts of the scientific workflow.
  • A unique integration with a scientific workflow: Mayavi exposes reusable abstractions rather than domain-specific cases, allowing similar visualization problems across research fields to share solutions.
  • Powerful underlying technologies: Mayavi is built on VTK, NumPy, Traits, TVTK, and optionally Envisage, connecting scientific arrays, visualization pipelines, and application interfaces.
  • A simple pipeline model for visualization: Mayavi provides a simplified pipeline in which sources produce data, filters modify it, and modules visualize it.
  • History of the project: Mayavi2 evolved from an interactive end-user application toward reuse and embedding after the original version was difficult to script from Python.

Using Mayavi

Mayavi offers several ways to create and explore 3D visualizations, from the no-code mayavi2 application to Python scripting and embeddable interactive components. Its simplified pipeline model supports both straightforward plotting and customizable, application-specific workflows.

  • Entry points: Mayavi provides multiple entry points, including the mayavi2 end-user application, Python interfaces, embeddable widgets, and Envisage plugins.The mayavi2 application supports visualization without programming, while other entry points support scripting and application development.
  • The mayavi2 application: The mayavi2 application presents a simplified tree-based pipeline for loading or creating data, applying filters, and configuring visualization modules.Modules provide a single point of entry for changing displayed-object properties, while shared color maps and legends can be separate pipeline nodes.
  • The mayavi2 application: Mayavi’s interactive application includes an IPython shell, object exploration, and recording tools that generate Python code for pipeline modifications.Recorded scripts are functional but may not be the simplest possible code.
  • Simple Python scripting: The mlab interface provides MATLAB- and matplotlib-inspired Python functions that operate on NumPy arrays and can run interactively or inside scripts and applications.Simple plotting commands can build complete visualization pipelines while hiding the pipeline model for basic use cases.
  • Simple Python scripting: Advanced mlab usage exposes sources, filters, and modules directly, enabling custom pipelines with broader possibilities but requiring understanding of Mayavi’s pipeline model.Pipeline function names correspond to the camel-case names of the represented classes, easing translation from interactive pipelines to scripts.
  • Embedding and extending applications: Mayavi components can be embedded in domain-specific applications, with wired callbacks, interactive property dialogs, and reusable widgets available to application builders.Traits-based interfaces support immediate visualization updates, while Mayavi dialogs can also be embedded in wxPython and PyQt applications.
  • Embedding and extending applications: The mayavi2 application can be extended through Envisage plugins that add custom functionality or domain-specific elements.The article illustrates this mechanism with a reader for NumPy arrays stored in text files.

Mayavi architecture and software design

Mayavi uses a layered, engine-centered architecture that separates visualization logic, scripting, and user interfaces. Reactive Traits, generated interfaces, and testing support reuse across applications and entry points.

  • Architecture: The architecture combines TVTK visualization objects, Mayavi pipeline objects, a central Engine, the mlab API, TraitsUI, and Envisage plugins.The Engine manages pipeline objects, while mlab controls it and Traits-based objects support UI panels and widgets.
  • Pipeline model: Pipeline objects expose inputs, outputs, parent-child relationships, and callbacks that rewire the underlying VTK pipeline when inputs change.The Engine can connect sources and modules implicitly or users can construct and connect the pipeline explicitly.
  • The Engine as a pipeline warden: The Engine maintains pipeline context and object lifecycles while allowing multiple isolated engines to avoid application and test side-effects.Any number of engines can be created and used simultaneously, supporting controlled visualization contexts and data-parallel execution.
  • Design choices: Traits-based reactive programming separates models from views, supports multiple UI backends, and avoids exposing GUI event-loop code to users.Trait assignments provide a thread-friendly message-passing style, although the MVC separation is not complete.
  • Design choices: Simple APIs, automatic code generation, scripting, and testing improve consistency, maintainability, reliability, and reusability.User interaction helped shape a consistent API, while unit tests, integration tests, TDD, and example scripts exposed unwanted coupling.
  • Design choices: Multiple abstraction layers separate concerns and share code across Mayavi’s graphical and programming entry points.A central registry specifies sources, filters, and modules and generates interface menus and many mlab.pipeline functions.

Some real-word applications

Mayavi supports scientific workflows ranging from scripted weather-model visualization to synchronized multi-computer displays and web-based notebook use. These applications combine interactive exploration with Python automation and extensibility.

  • Weather visualization: At NAL, Mayavi visualizes weather-simulation data and helps refine monsoon forecast models through interactive Python scripting.Recorded UI actions produce human-readable Python code that scientists can edit without detailed knowledge of Mayavi internals.
  • Weather visualization: Four Mayavi applications can be controlled over a network by a central program to provide a synchronized view.The NAL setup uses TCP and UDP communication to send Python statements and control camera positions across applications.
  • Weather visualization: The network-control server required about 90 lines of code and two additional lines in existing NAL scripts.The server used the Twisted library to interpret Python statements in running Mayavi applications.
  • Web-based visualization: Mayavi was integrated with a Sage notebook to support web-based visualization alongside interactive mathematical computing.Sage provides a Python-capable notebook interface for combining interpretable code, images, and text.

Conclusions

Mayavi provides reusable 3D visualization in Python, integrating scientific workflows across interactive, scripted, custom-application, and off-screen use.

  • Mayavi provides a rich, reusable 3D visualization package that integrates scientific computing and application development in Python.
  • Its consistent visualization model lets users prototype interactively and convert visualizations into embedded scripts or applications.
  • Mayavi supports workflows ranging from interactive end-user applications and scripts to custom applications and pure off-screen rendering.
  • The package is positioned as a natural, easy-to-use Python environment for 3D visualization.
Loading 1010.4891v1…