fipy.viewers.mayaviViewer package

Submodules

fipy.viewers.mayaviViewer.mayaviClient module

class fipy.viewers.mayaviViewer.mayaviClient.MayaviClient(vars, title=None, daemon_file=None, fps=1.0, **kwlimits)

Bases: AbstractViewer

The MayaviClient uses the Mayavi python plotting package.

>>> import fipy as fp
>>> mesh = fp.Grid1D(nx=100)
>>> x, = mesh.cellCenters
>>> xVar = fp.CellVariable(mesh=mesh, name="x", value=x)
>>> k = fp.Variable(name="k", value=0.)
>>> viewer = MayaviClient(vars=(fp.numerix.sin(k * xVar) + 2,
...                               fp.numerix.cos(k * xVar / fp.numerix.pi) + 2),
...                 xmin=10, xmax=90,
...                 datamin=1.1, datamax=4.0,
...                 title="MayaviClient test")
>>> for kval in fp.numerix.arange(0, 0.3, 0.03):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> import fipy as fp
>>> mesh = fp.Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = fp.CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = fp.Variable(name="k", value=0.)
>>> viewer = MayaviClient(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002,
...                 ymin=0.1, ymax=0.9,
...                 # datamin=1.1, datamax=4.0,
...                 title="MayaviClient test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> import fipy as fp
>>> mesh = (fp.Grid2D(nx=5, ny=10, dx=0.1, dy=0.1)
...         + (fp.Tri2D(nx=5, ny=5, dx=0.1, dy=0.1)
...          + ((0.5,), (0.2,))))
>>> x, y = mesh.cellCenters
>>> xyVar = fp.CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = fp.Variable(name="k", value=0.)
>>> viewer = MayaviClient(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002,
...                 ymin=0.1, ymax=0.9,
...                 # datamin=1.1, datamax=4.0,
...                 title="MayaviClient test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> import fipy as fp
>>> mesh = fp.Grid3D(nx=50, ny=100, nz=10, dx=0.1, dy=0.01, dz=0.1)
>>> x, y, z = mesh.cellCenters
>>> xyzVar = fp.CellVariable(mesh=mesh, name=r"x y z", value=x * y * z)
>>> k = fp.Variable(name="k", value=0.)
>>> viewer = MayaviClient(vars=fp.numerix.sin(k * xyzVar) + 2,
...                     ymin=0.1, ymax=0.9,
...                     datamin=1.1, datamax=4.0,
...                     title="MayaviClient test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()

Create a MayaviClient.

Parameters:
  • vars (CellVariable or list) – CellVariable objects to plot

  • title (str, optional) – displayed at the top of the Viewer window

  • xmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • xmax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • ymin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • ymax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • zmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • zmax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • datamin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • datamax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • daemon_file (str, optional) – the path to the script to run the separate Mayavi viewer process. Defaults to fipy/viewers/mayaviViewer/mayaviDaemon.py

  • fps (float, optional) – frames per second to attempt to display

__del__()
property fps

The frames per second to attempt to display.

property limits
plot(filename=None)

Update the display of the viewed variables.

Parameters:

filename (str) – If not None, the name of a file to save the image into.

plotMesh(filename=None)

Display a representation of the mesh

Parameters:

filename (str) – If not None, the name of a file to save the image into.

setLimits(limits={}, **kwlimits)

Update the limits.

Parameters:
  • limits (dict, optional) – a (deprecated) alternative to limit keyword arguments

  • xmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • xmax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • ymin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • ymax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • zmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • zmax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • datamin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • datamax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

property title

The text appearing at the top center.

(default: if len(self.vars) == 1, the name of self.vars[0], otherwise "".)

property vars

The Variable or list of Variable objects to display.

fipy.viewers.mayaviViewer.mayaviDaemon module

A simple script that polls a data file for changes and then updates the Mayavi pipeline automatically.

This script is based heavily on the poll_file.py example in the Mayavi distribution.

This script is to be run like so:

$ mayavi2 -x mayaviDaemon.py <options>

Or:

$ python mayaviDaemon.py <options>

Run:

$ python mayaviDaemon.py --help

to see available options.

class fipy.viewers.mayaviViewer.mayaviDaemon.MayaviDaemon

Bases: Mayavi

Given a file name and a mayavi2 data reader object, this class polls the file for any changes and automatically updates the mayavi pipeline.

__base_traits__ = {'application': <traits.ctrait.CTrait object>, 'log_mode': <traits.ctrait.CTrait object>, 'script': <traits.ctrait.CTrait object>, 'start_gui_event_loop': <traits.ctrait.CTrait object>, 'trait_added': <traits.ctrait.CTrait object>, 'trait_modified': <traits.ctrait.CTrait object>}
__class_traits__ = {'application': <traits.ctrait.CTrait object>, 'log_mode': <traits.ctrait.CTrait object>, 'script': <traits.ctrait.CTrait object>, 'start_gui_event_loop': <traits.ctrait.CTrait object>, 'trait_added': <traits.ctrait.CTrait object>, 'trait_modified': <traits.ctrait.CTrait object>}
__del__()
__delattr__(name, /)

Implement delattr(self, name).

__getattribute__(name, /)

Return getattr(self, name).

__instance_traits__ = {}
__listener_traits__ = {'_on_application_gui_started': ('method', {'pattern': 'application.gui:started', 'post_init': False, 'dispatch': 'same'})}
__observer_traits__ = {}
__prefix_traits__ = {'': <traits.ctrait.CTrait object>, '*': ['_traits_cache_', ''], '_traits_cache_': <traits.ctrait.CTrait object>}
__setattr__(name, value, /)

Implement setattr(self, name, value).

__view_traits__ = {}
classmethod add_class_trait(name, *trait)

Adds a named trait attribute to this class.

Also adds the same attribute to all subclasses.

Parameters:
  • name (str) – Name of the attribute to add.

  • *trait – A trait or a value that can be converted to a trait using Trait() Trait definition of the attribute. It can be a single value or a list equivalent to an argument list for the Trait() function.

classmethod class_default_traits_view()

Returns the name of the default traits view for the class.

classmethod class_editable_traits()

Returns an alphabetically sorted list of the names of non-event trait attributes associated with the current class.

classmethod class_trait_names(**metadata)

Returns a list of the names of all trait attributes whose definitions match the set of metadata criteria specified.

This method is similar to the traits() method, but returns only the names of the matching trait attributes, not the trait definitions.

Parameters:

**metadata – Criteria for selecting trait attributes.

classmethod class_trait_view(name=None, view_element=None)
classmethod class_trait_view_elements()

Returns the ViewElements object associated with the class.

The returned object can be used to access all the view elements associated with the class.

classmethod class_traits(**metadata)

Returns a dictionary containing the definitions of all of the trait attributes of the class that match the set of metadata criteria.

The keys of the returned dictionary are the trait attribute names, and the values are their corresponding trait definition objects.

If no metadata information is specified, then all explicitly defined trait attributes defined for the class are returned.

Otherwise, the metadata keyword dictionary is assumed to define a set of search criteria for selecting trait attributes of interest. The metadata dictionary keys correspond to the names of trait metadata attributes to examine, and the values correspond to the values the metadata attribute must have in order to be included in the search results.

The metadata values either may be simple Python values like strings or integers, or may be lambda expressions or functions that return True if the trait attribute is to be included in the result. A lambda expression or function must receive a single argument, which is the value of the trait metadata attribute being tested. If more than one metadata keyword is specified, a trait attribute must match the metadata values of all keywords to be included in the result.

Parameters:

**metadata – Criteria for selecting trait attributes.

classmethod class_visible_traits()

Returns an alphabetically sorted list of the names of non-event trait attributes associated with the current class, that should be GUI visible

clip_data(src)
parse_command_line(argv)

Parse command line options.

Parameters:

argv (list of str) – The command line arguments

poll_file()
run()

This function is called after the GUI has started. Override this to do whatever you want to do as a MayaVi script. If this is not overridden then an empty MayaVi application will be started.

Make sure all other MayaVi specific imports are made here! If you import MayaVi related code earlier you will run into difficulties. Use ‘self.script’ to script the mayavi engine.

classmethod set_trait_dispatch_handler(name, klass, override=False)

Sets a trait notification dispatch handler.

setup_source(fname)

Given a VTK file name fname, this creates a mayavi2 reader for it and adds it to the pipeline. It returns the reader created.

trait_added

An event fired when a new trait is dynamically added to the object. The value is the name of the trait that was added.

trait_items_event(name, event_object, event_trait)

Fire an items event for changes to a Traits collection.

Parameters:
  • name (str) – Name of the item trait for which an event is being fired. (The name will usually end in ‘_items’.)

  • event_object (object) – Object of type TraitListEvent, TraitDictEvent or TraitSetEvent describing the changes to the underlying collection trait value.

  • event_trait (CTrait) – The items trait, of trait type Event.

trait_modified

An event that can be fired to indicate that the state of the object has been modified.

trait_property_changed(name, old_value[, new_value])

Call notifiers when a trait property value is explicitly changed.

Calls trait and object notifiers for a property value change.

Parameters:
  • name (str) – Name of the trait whose value has changed

  • old_value (any) – Old value for this trait.

  • new_value (any, optional) – New value for this trait. If the new value is not provided, it’s looked up on the object.

classmethod trait_subclasses(all=False)

Returns a list of the immediate (or all) subclasses of this class.

Parameters:

all (bool) – Indicates whether to return all subclasses of this class. If False, only immediate subclasses are returned.

traits_init()

Perform any final object initialization needed.

For the CHasTraits base class, this method currently does nothing.

traits_inited()

Get the initialization state of this object.

Returns:

initialized – True if the object is initialized, else False.

Return type:

bool

update_pipeline(source)

Override this to do something else if needed.

view_data()

Sets up the mayavi pipeline for the visualization.

wrappers = {'extended': <class 'traits.trait_notifiers.ExtendedTraitChangeNotifyWrapper'>, 'fast_ui': <class 'traits.trait_notifiers.FastUITraitChangeNotifyWrapper'>, 'new': <class 'traits.trait_notifiers.NewTraitChangeNotifyWrapper'>, 'same': <class 'traits.trait_notifiers.TraitChangeNotifyWrapper'>, 'ui': <class 'traits.trait_notifiers.FastUITraitChangeNotifyWrapper'>}

Mapping from dispatch type to notification wrapper class type

fipy.viewers.mayaviViewer.test module

Test numeric implementation of the mesh

Module contents

class fipy.viewers.mayaviViewer.MayaviClient(vars, title=None, daemon_file=None, fps=1.0, **kwlimits)

Bases: AbstractViewer

The MayaviClient uses the Mayavi python plotting package.

>>> import fipy as fp
>>> mesh = fp.Grid1D(nx=100)
>>> x, = mesh.cellCenters
>>> xVar = fp.CellVariable(mesh=mesh, name="x", value=x)
>>> k = fp.Variable(name="k", value=0.)
>>> viewer = MayaviClient(vars=(fp.numerix.sin(k * xVar) + 2,
...                               fp.numerix.cos(k * xVar / fp.numerix.pi) + 2),
...                 xmin=10, xmax=90,
...                 datamin=1.1, datamax=4.0,
...                 title="MayaviClient test")
>>> for kval in fp.numerix.arange(0, 0.3, 0.03):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> import fipy as fp
>>> mesh = fp.Grid2D(nx=50, ny=100, dx=0.1, dy=0.01)
>>> x, y = mesh.cellCenters
>>> xyVar = fp.CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = fp.Variable(name="k", value=0.)
>>> viewer = MayaviClient(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002,
...                 ymin=0.1, ymax=0.9,
...                 # datamin=1.1, datamax=4.0,
...                 title="MayaviClient test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> import fipy as fp
>>> mesh = (fp.Grid2D(nx=5, ny=10, dx=0.1, dy=0.1)
...         + (fp.Tri2D(nx=5, ny=5, dx=0.1, dy=0.1)
...          + ((0.5,), (0.2,))))
>>> x, y = mesh.cellCenters
>>> xyVar = fp.CellVariable(mesh=mesh, name="x y", value=x * y)
>>> k = fp.Variable(name="k", value=0.)
>>> viewer = MayaviClient(vars=fp.numerix.sin(k * xyVar) * 1000 + 1002,
...                 ymin=0.1, ymax=0.9,
...                 # datamin=1.1, datamax=4.0,
...                 title="MayaviClient test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()
>>> import fipy as fp
>>> mesh = fp.Grid3D(nx=50, ny=100, nz=10, dx=0.1, dy=0.01, dz=0.1)
>>> x, y, z = mesh.cellCenters
>>> xyzVar = fp.CellVariable(mesh=mesh, name=r"x y z", value=x * y * z)
>>> k = fp.Variable(name="k", value=0.)
>>> viewer = MayaviClient(vars=fp.numerix.sin(k * xyzVar) + 2,
...                     ymin=0.1, ymax=0.9,
...                     datamin=1.1, datamax=4.0,
...                     title="MayaviClient test")
>>> from builtins import range
>>> for kval in range(10):
...     k.setValue(kval)
...     viewer.plot()
>>> viewer._promptForOpinion()

Create a MayaviClient.

Parameters:
  • vars (CellVariable or list) – CellVariable objects to plot

  • title (str, optional) – displayed at the top of the Viewer window

  • xmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • xmax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • ymin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • ymax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • zmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • zmax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • datamin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • datamax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • daemon_file (str, optional) – the path to the script to run the separate Mayavi viewer process. Defaults to fipy/viewers/mayaviViewer/mayaviDaemon.py

  • fps (float, optional) – frames per second to attempt to display

__del__()
property fps

The frames per second to attempt to display.

property limits
plot(filename=None)

Update the display of the viewed variables.

Parameters:

filename (str) – If not None, the name of a file to save the image into.

plotMesh(filename=None)

Display a representation of the mesh

Parameters:

filename (str) – If not None, the name of a file to save the image into.

setLimits(limits={}, **kwlimits)

Update the limits.

Parameters:
  • limits (dict, optional) – a (deprecated) alternative to limit keyword arguments

  • xmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • xmax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • ymin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • ymax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • zmin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • zmax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • datamin (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

  • datamax (float, optional) – displayed range of data. A 1D Viewer will only use xmin and xmax, a 2D viewer will also use ymin and ymax, and so on. All viewers will use datamin and datamax. Any limit set to a (default) value of None will autoscale.

property title

The text appearing at the top center.

(default: if len(self.vars) == 1, the name of self.vars[0], otherwise "".)

property vars

The Variable or list of Variable objects to display.

Last updated on Jun 27, 2023. Created using Sphinx 6.2.1.