def __init__(self, vars, title=None, limits={}, **kwlimits):
        """
        Creates a `TSVViewer`.

        Any cell centers that lie outside the limits provided will not be included.
        Any values that lie outside the *datamin* or *datamax* will be 
        replaced with `nan`.
        
        All variables must have the same mesh.
            
        It tries to do something reasonable with rank-1 `CellVariable` and `FaceVariable` objects.


        :Parameters:
          vars
            a `CellVariable`, a `FaceVariable`, a tuple of `CellVariable`
            objects, or a tuple of `FaceVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          limits : dict
            a (deprecated) alternative to limit keyword arguments
          xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax
            displayed range of data. Any limit set to 
            a (default) value of `None` will autoscale.
        """
        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        mesh = self.vars[0].mesh

        for var in self.vars:
            assert mesh is var.mesh
Exemple #2
0
    def __init__(self, vars, title=None, limits={}, **kwlimits):
        """
        Creates a `TSVViewer`.

        Any cell centers that lie outside the limits provided will not be included.
        Any values that lie outside the *datamin* or *datamax* will be 
        replaced with `nan`.
        
        All variables must have the same mesh.
            
        It tries to do something reasonable with rank-1 `CellVariable` and `FaceVariable` objects.


        :Parameters:
          vars
            a `CellVariable`, a `FaceVariable`, a tuple of `CellVariable`
            objects, or a tuple of `FaceVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          limits : dict
            a (deprecated) alternative to limit keyword arguments
          xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax
            displayed range of data. Any limit set to 
            a (default) value of `None` will autoscale.
        """
        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)
        
        mesh = self.vars[0].mesh
        
        for var in self.vars:
            assert mesh is var.mesh
Exemple #3
0
    def __init__(self, vars, title=None, dpi=75, **kwlimits):
        """
        Create a `_GistViewer` object.
        
        :Parameters:
          vars
            a `CellVariable` or tuple of `CellVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          dpi
            the dot-per-inch resolution of the display
          xmin, xmax, ymin, ymax, datamin, datamax
            displayed range of data. A 1D `Viewer` will only use `xmin` and
            `xmax`, a 2D viewer will also use `ymin` and `ymax`. All
            viewers will use `datamin` and `datamax`. Any limit set to a
            (default) value of `None` will autoscale.
        """
        if self.__class__ is _GistViewer:
            raise NotImplementedError, "can't instantiate abstract base class"
    
        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)
        
        self.mesh = self.vars[0].mesh

        self.id = _GistViewer._id 
        _GistViewer._id += 1
        
        import gist
        
        gist.window(self.id, wait = 1, dpi = dpi, display = '')
Exemple #4
0
    def __init__(self, vars, title=None, limits={}, **kwlimits):
        """Creates a VTKViewer

        :Parameters:
          vars
            a `_MeshVariable` or a tuple of them
          title
            displayed at the top of the `Viewer` window
          limits : dict
            a (deprecated) alternative to limit keyword arguments
          xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax
            displayed range of data. Any limit set to 
            a (default) value of `None` will autoscale.
        """
        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        mesh = self.vars[0].mesh

        self.dataset = self._makeDataSet(mesh)

        data = self._data

        for var in self.vars:
            name, rank, value = self._nameRankValue(var)

            i = data.add_array(value)
            data.get_array(i).name = name

            if rank == 0:
                data.set_active_scalars(name)
            elif rank == 1:
                data.set_active_vectors(name)
            else:
                data.set_active_tensors(name)
Exemple #5
0
    def __init__(self, vars, title=None, dpi=75, **kwlimits):
        """
        Create a `_GistViewer` object.
        
        :Parameters:
          vars
            a `CellVariable` or tuple of `CellVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          dpi
            the dot-per-inch resolution of the display
          xmin, xmax, ymin, ymax, datamin, datamax
            displayed range of data. A 1D `Viewer` will only use `xmin` and
            `xmax`, a 2D viewer will also use `ymin` and `ymax`. All
            viewers will use `datamin` and `datamax`. Any limit set to a
            (default) value of `None` will autoscale.
        """
        if self.__class__ is _GistViewer:
            raise NotImplementedError, "can't instantiate abstract base class"

        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        self.mesh = self.vars[0].mesh

        self.id = _GistViewer._id
        _GistViewer._id += 1

        import gist

        gist.window(self.id, wait=1, dpi=dpi, display='')
Exemple #6
0
    def __init__(self, vars, title=None, limits={}, **kwlimits):
        """
        Creates a `TSVViewer`.

        Any cell centers that lie outside the limits provided will not be included.
        Any values that lie outside the `datamin` or `datamax` will be
        replaced with `nan`.

        All variables must have the same mesh.

        It tries to do something reasonable with rank-1 `CellVariable` and `FaceVariable` objects.

        Parameters
        ----------
        vars : ~fipy.variables.cellVariable.CellVariable or ~fipy.variables.faceVariable.FaceVariable or list
            the `MeshVariable` objects to display.
        title : str, optional
            displayed at the top of the `Viewer` window
        limits : dict, optional
            a (deprecated) alternative to limit keyword arguments
        float xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax : float, optional
            displayed range of data. Any limit set to
            a (default) value of `None` will autoscale.
        """
        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        mesh = self.vars[0].mesh

        for var in self.vars:
            assert mesh is var.mesh
Exemple #7
0
    def __init__(self, vars, title=None, limits={}, **kwlimits):
        """Creates a VTKViewer

        :Parameters:
          vars
            a `_MeshVariable` or a tuple of them
          title
            displayed at the top of the `Viewer` window
          limits : dict
            a (deprecated) alternative to limit keyword arguments
          xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax
            displayed range of data. Any limit set to
            a (default) value of `None` will autoscale.
        """
        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        mesh = self.vars[0].mesh

        self.dataset = self._makeDataSet(mesh)

        data = self._data

        for var in self.vars:
            name, rank, value = self._nameRankValue(var)

            i = data.add_array(value)
            data.get_array(i).name = name

            if rank == 0:
                data.set_active_scalars(name)
            elif rank == 1:
                data.set_active_vectors(name)
            else:
                data.set_active_tensors(name)
Exemple #8
0
    def __init__(self, vars, title=None, **kwlimits):
        """
        The `_GnuplotViewer` should not be called directly only `Gnuplot1DViewer`
        and `Gnuplot2DViewer` should be called.
        
        :Parameters:
          vars
            a `CellVariable` or tuple of `CellVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          xmin, xmax, ymin, ymax, datamin, datamax
            displayed range of data. A 1D `Viewer` will only use `xmin` and
            `xmax`, a 2D viewer will also use `ymin` and `ymax`. All
            viewers will use `datamin` and `datamax`. Any limit set to a
            (default) value of `None` will autoscale.
        """
        if self.__class__ is _GnuplotViewer:
            raise NotImplementedError("can't instantiate abstract base class")

        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)
        import Gnuplot
        self.g = Gnuplot.Gnuplot()
        self.g('set title "' + self.title + '"')
Exemple #9
0
 def __init__(self, vars, title=None, **kwlimits):
     """
     The `_GnuplotViewer` should not be called directly only `Gnuplot1DViewer`
     and `Gnuplot2DViewer` should be called.
     
     :Parameters:
       vars
         a `CellVariable` or tuple of `CellVariable` objects to plot
       title
         displayed at the top of the `Viewer` window
       xmin, xmax, ymin, ymax, datamin, datamax
         displayed range of data. A 1D `Viewer` will only use `xmin` and
         `xmax`, a 2D viewer will also use `ymin` and `ymax`. All
         viewers will use `datamin` and `datamax`. Any limit set to a
         (default) value of `None` will autoscale.
     """
     if self.__class__ is _GnuplotViewer:
         raise NotImplementedError, "can't instantiate abstract base class"
 
     AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)
     import Gnuplot
     self.g = Gnuplot.Gnuplot()
     self.g('set title "' + self.title + '"')
Exemple #10
0
    def __init__(self, vars, title=None, limits={}, **kwlimits):
        """Creates a `VTKViewer`

        Parameters
        ----------
        vars : ~fipy.variables.cellVariable.CellVariable or ~fipy.variables.faceVariable.FaceVariable or list
            the `MeshVariable` objects to display.
        title : str, optional
            displayed at the top of the `Viewer` window
        limits : dict, optional
            a (deprecated) alternative to limit keyword arguments
        float xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax : float, optional
            displayed range of data. Any limit set to
            a (default) value of `None` will autoscale.
        """
        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        mesh = self.vars[0].mesh

        self.dataset = self._makeDataSet(mesh)

        data = self._data

        for var in self.vars:
            name, rank, value = self._nameRankValue(var)

            i = data.add_array(value)
            data.get_array(i).name = name

            if rank == 0:
                data.set_active_scalars(name)
            elif rank == 1:
                data.set_active_vectors(name)
            else:
                data.set_active_tensors(name)
Exemple #11
0
    def _getLimit(self, key, default=None):
        """
        Return the limit associated with the key

        .. Note::

           `MayaviClient` does not need the generality of multiple keys
           because it is always 3D

        :Parameters:
          key
            a key string that identifies the limit of interest

        :Returns:
          the value of the limit or `None`
        """
        lim = AbstractViewer._getLimit(self, key, default=None)
        if lim is not None:
            return ["--%s" % key, str(lim)]
        else:
            return []
Exemple #12
0
    def _getLimit(self, key, default=None):
        """
        Return the limit associated with the key

        .. Note::

           `MayaviClient` does not need the generality of multiple keys
           because it is always 3D

        :Parameters:
          key
            a key string that identifies the limit of interest

        :Returns:
          the value of the limit or `None`
        """
        lim = AbstractViewer._getLimit(self, key, default=None)
        if lim is not None:
            return ["--%s" % key, str(lim)]
        else:
            return []
Exemple #13
0
    def _getLimit(self, key, default=None):
        """
        Return the limit associated with the key

        .. Note::

           `MayaviClient` does not need the generality of multiple keys
           because it is always 3D

        Parameters
        ----------
        key : str
            dictionary key that identifies the limit of interest

        Returns
        -------
        float or None
            the value of the limit
        """
        lim = AbstractViewer._getLimit(self, key, default=None)
        if lim is not None:
            return ["--%s" % key, str(lim)]
        else:
            return []
Exemple #14
0
    def __init__(self, vars, title=None, figaspect=1.0, cmap=None, colorbar=None, axes=None, log=False, **kwlimits):
        """
        Create a `AbstractMatplotlibViewer`.
        
        :Parameters:
          vars
            a `CellVariable` or tuple of `CellVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          figaspect
            desired aspect ratio of figure. If arg is a number, use that aspect
            ratio. If arg is an array, figaspect will determine the width and
            height for a figure that would fit array preserving aspect ratio.
          xmin, xmax, ymin, ymax, datamin, datamax
            displayed range of data. A 1D `Viewer` will only use `xmin` and
            `xmax`, a 2D viewer will also use `ymin` and `ymax`. All
            viewers will use `datamin` and `datamax`. Any limit set to a
            (default) value of `None` will autoscale.
          cmap
            the colormap. Defaults to `matplotlib.cm.jet`
          colorbar
            plot a colorbar in specified orientation if not `None`
          axes
            if not `None`, `vars` will be plotted into this Matplotlib `Axes` object
          log
            whether to logarithmically scale the data
        """
        if self.__class__ is AbstractMatplotlibViewer:
            raise NotImplementedError, "can't instantiate abstract base class"
            
        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        import pylab

        pylab.ion()

        if axes is None:
            w, h = pylab.figaspect(self.figaspect(figaspect))
            fig = pylab.figure(figsize=(w, h))
            self.axes = pylab.gca()
        else:
            self.axes = axes
            fig = axes.get_figure()
            
        self.id = fig.number
        
        self.axes.set_title(self.title)
        
        import matplotlib
        # Set the colormap and norm to correspond to the data for which
        # the colorbar will be used.
        if cmap is None:
            self.cmap = matplotlib.cm.jet
        else:
            self.cmap = cmap
            
        if colorbar:
            self.colorbar = _ColorBar(viewer=self)
        else:
            self.colorbar = None

        self.norm = None
        self.log = log 
Exemple #15
0
    def __init__(self,
                 vars,
                 title=None,
                 daemon_file=None,
                 fps=1.0,
                 **kwlimits):
        """
        Create a `MayaviClient`.

        :Parameters:
          vars
            a `CellVariable` or tuple of `CellVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax
            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
            the path to the script to run the separate Mayavi viewer process.
            Defaults to "fipy/viewers/mayaviViewer/mayaviDaemon.py"
          fps
            frames per second to attempt to display
        """
        self.fps = fps

        self.vtkdir = tempfile.mkdtemp()
        self.vtkcellfname = os.path.join(self.vtkdir, "cell.vtk")
        self.vtkfacefname = os.path.join(self.vtkdir, "face.vtk")
        self.vtklockfname = os.path.join(self.vtkdir, "lock")

        from fipy.viewers.vtkViewer import VTKCellViewer, VTKFaceViewer

        try:
            self.vtkCellViewer = VTKCellViewer(vars=vars)
            cell_vars = self.vtkCellViewer.vars
        except TypeError:
            self.vtkCellViewer = None
            cell_vars = []

        try:
            self.vtkFaceViewer = VTKFaceViewer(vars=vars)
            face_vars = self.vtkFaceViewer.vars
        except TypeError:
            self.vtkFaceViewer = None
            face_vars = []

        AbstractViewer.__init__(self,
                                vars=cell_vars + face_vars,
                                title=title,
                                **kwlimits)

        self.plot()

        from pkg_resources import Requirement, resource_filename
        daemon_file = (daemon_file or resource_filename(
            Requirement.parse("FiPy"),
            "fipy/viewers/mayaviViewer/mayaviDaemon.py"))

        cmd = [
            "python", daemon_file, "--lock", self.vtklockfname, "--fps",
            str(self.fps)
        ]

        if self.vtkCellViewer is not None:
            cmd += ["--cell", self.vtkcellfname]

        if self.vtkFaceViewer is not None:
            cmd += ["--face", self.vtkfacefname]

        cmd += self._getLimit('xmin')
        cmd += self._getLimit('xmax')
        cmd += self._getLimit('ymin')
        cmd += self._getLimit('ymax')
        cmd += self._getLimit('zmin')
        cmd += self._getLimit('zmax')
        cmd += self._getLimit('datamin')
        cmd += self._getLimit('datamax')

        self.daemon = subprocess.Popen(cmd)
Exemple #16
0
class MayaviClient(AbstractViewer):
    """
    The `MayaviClient` uses the Mayavi_ python plotting package.

    .. _Mayavi: http://code.enthought.com/projects/mayavi

    """
    __doc__ += AbstractViewer._test1D(viewer="MayaviClient")
    __doc__ += AbstractViewer._test2D(viewer="MayaviClient")
    __doc__ += AbstractViewer._test2Dirregular(viewer="MayaviClient")
    __doc__ += AbstractViewer._test3D(viewer="MayaviClient")

    def __init__(self,
                 vars,
                 title=None,
                 daemon_file=None,
                 fps=1.0,
                 **kwlimits):
        """
        Create a `MayaviClient`.

        :Parameters:
          vars
            a `CellVariable` or tuple of `CellVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax
            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
            the path to the script to run the separate Mayavi viewer process.
            Defaults to "fipy/viewers/mayaviViewer/mayaviDaemon.py"
          fps
            frames per second to attempt to display
        """
        self.fps = fps

        self.vtkdir = tempfile.mkdtemp()
        self.vtkcellfname = os.path.join(self.vtkdir, "cell.vtk")
        self.vtkfacefname = os.path.join(self.vtkdir, "face.vtk")
        self.vtklockfname = os.path.join(self.vtkdir, "lock")

        from fipy.viewers.vtkViewer import VTKCellViewer, VTKFaceViewer

        try:
            self.vtkCellViewer = VTKCellViewer(vars=vars)
            cell_vars = self.vtkCellViewer.vars
        except TypeError:
            self.vtkCellViewer = None
            cell_vars = []

        try:
            self.vtkFaceViewer = VTKFaceViewer(vars=vars)
            face_vars = self.vtkFaceViewer.vars
        except TypeError:
            self.vtkFaceViewer = None
            face_vars = []

        AbstractViewer.__init__(self,
                                vars=cell_vars + face_vars,
                                title=title,
                                **kwlimits)

        self.plot()

        from pkg_resources import Requirement, resource_filename
        daemon_file = (daemon_file or resource_filename(
            Requirement.parse("FiPy"),
            "fipy/viewers/mayaviViewer/mayaviDaemon.py"))

        cmd = [
            "python", daemon_file, "--lock", self.vtklockfname, "--fps",
            str(self.fps)
        ]

        if self.vtkCellViewer is not None:
            cmd += ["--cell", self.vtkcellfname]

        if self.vtkFaceViewer is not None:
            cmd += ["--face", self.vtkfacefname]

        cmd += self._getLimit('xmin')
        cmd += self._getLimit('xmax')
        cmd += self._getLimit('ymin')
        cmd += self._getLimit('ymax')
        cmd += self._getLimit('zmin')
        cmd += self._getLimit('zmax')
        cmd += self._getLimit('datamin')
        cmd += self._getLimit('datamax')

        self.daemon = subprocess.Popen(cmd)

    def __del__(self):
        for fname in [self.vtkcellfname, self.vtkfacefname, self.vtklockfname]:
            if fname and os.path.isfile(fname):
                os.unlink(fname)
        os.rmdir(self.vtkdir)

    def _getLimit(self, key, default=None):
        """
        Return the limit associated with the key

        .. Note::

           `MayaviClient` does not need the generality of multiple keys
           because it is always 3D

        :Parameters:
          key
            a key string that identifies the limit of interest

        :Returns:
          the value of the limit or `None`
        """
        lim = AbstractViewer._getLimit(self, key, default=None)
        if lim is not None:
            return ["--%s" % key, str(lim)]
        else:
            return []

    def plot(self, filename=None):
        start = time.time()
        plotted = False
        while not plotted:
            if not os.path.isfile(self.vtklockfname):
                if self.vtkCellViewer is not None:
                    self.vtkCellViewer.plot(filename=self.vtkcellfname)
                if self.vtkFaceViewer is not None:
                    self.vtkFaceViewer.plot(filename=self.vtkfacefname)
                lock = file(self.vtklockfname, 'w')
                if filename is not None:
                    lock.write(filename)
                lock.close()
                plotted = True

            if (time.time() - start > 30. / self.fps) and not plotted:
                print "viewer: NOT READY"
                start = time.time()
        if not plotted:
            print "viewer: SKIPPED"

    def _validFileExtensions(self):
        return [
            ".png", ".jpg", ".bmp", ".tiff", ".ps", ".eps", ".pdf", ".rib",
            ".oogl", ".iv", ".vrml", ".obj"
        ]
    def __init__(self, distanceVar, surfactantVar=None, levelSetValue=0., title=None, smooth=0, zoomFactor=1., animate=False, limits={}, **kwlimits):
        """
        Create a `MayaviSurfactantViewer`.

            >>> from fipy import *
            >>> dx = 1.
            >>> dy = 1.
            >>> nx = 11
            >>> ny = 11
            >>> Lx = ny * dy
            >>> Ly = nx * dx
            >>> mesh = Grid2D(dx = dx, dy = dy, nx = nx, ny = ny)
            >>> # from fipy.models.levelSet.distanceFunction.distanceVariable import DistanceVariable
            >>> var = DistanceVariable(mesh = mesh, value = -1)

            >>> x, y = mesh.cellCenters

            >>> var.setValue(1, where=(x - Lx / 2.)**2 + (y - Ly / 2.)**2 < (Lx / 4.)**2)
            >>> var.calcDistanceFunction()
            >>> viewer = MayaviSurfactantViewer(var, smooth = 2)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

            >>> var = DistanceVariable(mesh = mesh, value = -1)

            >>> var.setValue(1, where=(y > 2. * Ly / 3.) | ((x > Lx / 2.) & (y > Ly / 3.)) | ((y < Ly / 6.) & (x > Lx / 2)))
            >>> var.calcDistanceFunction()
            >>> viewer = MayaviSurfactantViewer(var)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

            >>> viewer = MayaviSurfactantViewer(var, smooth = 2)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

        :Parameters:

          - `distanceVar`: a `DistanceVariable` object.
          - `levelSetValue`: the value of the contour to be displayed
          - `title`: displayed at the top of the `Viewer` window
          - `animate`: whether to show only the initial condition and the
          - `limits`: a dictionary with possible keys `xmin`, `xmax`,
            `ymin`, `ymax`, `zmin`, `zmax`, `datamin`, `datamax`.  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.
            moving top boundary or to show all contours (Default)
        """

        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=[], title=title, **kwlimits)
        import mayavi
        self._viewer = mayavi.mayavi()
        self.distanceVar = distanceVar
        if surfactantVar is None:
            self.surfactantVar = numerix.zeros(len(self.distanceVar), 'd')
        else:
            self.surfactantVar = surfactantVar
        self.smooth = smooth
        self.zoomFactor = zoomFactor

        self.animate = animate
        if animate:
            self._initialCondition = None

        if distanceVar.mesh.dim != 2:
            raise MeshDimensionError('The MayaviIsoViewer only works for 2D meshes.')
Exemple #18
0
    def __init__(self,
                 distanceVar,
                 surfactantVar=None,
                 levelSetValue=0.,
                 title=None,
                 smooth=0,
                 zoomFactor=1.,
                 animate=False,
                 limits={},
                 **kwlimits):
        """
        Create a `MayaviSurfactantViewer`.

            >>> from fipy import *
            >>> dx = 1.
            >>> dy = 1.
            >>> nx = 11
            >>> ny = 11
            >>> Lx = ny * dy
            >>> Ly = nx * dx
            >>> mesh = Grid2D(dx = dx, dy = dy, nx = nx, ny = ny)
            >>> # from fipy.models.levelSet.distanceFunction.distanceVariable import DistanceVariable
            >>> var = DistanceVariable(mesh = mesh, value = -1)

            >>> x, y = mesh.cellCenters

            >>> var.setValue(1, where=(x - Lx / 2.)**2 + (y - Ly / 2.)**2 < (Lx / 4.)**2)
            >>> var.calcDistanceFunction()
            >>> viewer = MayaviSurfactantViewer(var, smooth = 2)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

            >>> var = DistanceVariable(mesh = mesh, value = -1)

            >>> var.setValue(1, where=(y > 2. * Ly / 3.) | ((x > Lx / 2.) & (y > Ly / 3.)) | ((y < Ly / 6.) & (x > Lx / 2)))
            >>> var.calcDistanceFunction()
            >>> viewer = MayaviSurfactantViewer(var)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

            >>> viewer = MayaviSurfactantViewer(var, smooth = 2)
            >>> viewer.plot()
            >>> viewer._promptForOpinion()
            >>> del viewer

        :Parameters:

          - `distanceVar`: a `DistanceVariable` object.
          - `levelSetValue`: the value of the contour to be displayed
          - `title`: displayed at the top of the `Viewer` window
          - `animate`: whether to show only the initial condition and the
          - `limits`: a dictionary with possible keys `xmin`, `xmax`,
            `ymin`, `ymax`, `zmin`, `zmax`, `datamin`, `datamax`.  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.
            moving top boundary or to show all contours (Default)
        """

        kwlimits.update(limits)
        AbstractViewer.__init__(self, vars=[], title=title, **kwlimits)
        import mayavi
        self._viewer = mayavi.mayavi()
        self.distanceVar = distanceVar
        if surfactantVar is None:
            self.surfactantVar = numerix.zeros(len(self.distanceVar), 'd')
        else:
            self.surfactantVar = surfactantVar
        self.smooth = smooth
        self.zoomFactor = zoomFactor

        self.animate = animate
        if animate:
            self._initialCondition = None

        if distanceVar.mesh.dim != 2:
            raise MeshDimensionError(
                'The MayaviIsoViewer only works for 2D meshes.')
Exemple #19
0
 def _getLimit(self, keys, default='e'):
     return AbstractViewer._getLimit(self, keys=keys, default=default)
Exemple #20
0
 def _getLimit(self, key, default=''):
     return str(AbstractViewer._getLimit(self, key, default=default))
Exemple #21
0
    def __init__(self,
                 vars,
                 title=None,
                 figaspect=1.0,
                 cmap=None,
                 colorbar=None,
                 axes=None,
                 log=False,
                 **kwlimits):
        """
        Create a `AbstractMatplotlibViewer`.
        
        :Parameters:
          vars
            a `CellVariable` or tuple of `CellVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          figaspect
            desired aspect ratio of figure. If arg is a number, use that aspect
            ratio. If arg is an array, figaspect will determine the width and
            height for a figure that would fit array preserving aspect ratio.
          xmin, xmax, ymin, ymax, datamin, datamax
            displayed range of data. A 1D `Viewer` will only use `xmin` and
            `xmax`, a 2D viewer will also use `ymin` and `ymax`. All
            viewers will use `datamin` and `datamax`. Any limit set to a
            (default) value of `None` will autoscale.
          cmap
            the colormap. Defaults to `matplotlib.cm.jet`
          colorbar
            plot a colorbar in specified orientation if not `None`
          axes
            if not `None`, `vars` will be plotted into this Matplotlib `Axes` object
          log
            whether to logarithmically scale the data
        """
        if self.__class__ is AbstractMatplotlibViewer:
            raise NotImplementedError("can't instantiate abstract base class")

        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        import pylab

        pylab.ion()

        if axes is None:
            w, h = pylab.figaspect(self.figaspect(figaspect))
            fig = pylab.figure(figsize=(w, h))
            self.axes = pylab.gca()
        else:
            self.axes = axes
            fig = axes.get_figure()

        self.id = fig.number

        self.axes.set_title(self.title)

        import matplotlib
        # Set the colormap and norm to correspond to the data for which
        # the colorbar will be used.
        if cmap is None:
            self.cmap = matplotlib.cm.jet
        else:
            self.cmap = cmap

        if colorbar:
            self.colorbar = _ColorBar(viewer=self)
        else:
            self.colorbar = None

        self.norm = None
        self.log = log
Exemple #22
0
 def _getLimit(self, keys, default='e'):
     return AbstractViewer._getLimit(self, keys=keys, default=default)
Exemple #23
0
 def _getLimit(self, key, default=''):
     return str(AbstractViewer._getLimit(self, key, default=default))
Exemple #24
0
    def __init__(self,
                 vars,
                 title=None,
                 figaspect=1.0,
                 cmap=None,
                 colorbar=None,
                 axes=None,
                 log=False,
                 **kwlimits):
        """
        Create a `AbstractMatplotlibViewer`.

        Parameters
        ----------
        vars : ~fipy.variables.cellVariable.CellVariable or list
            the `Variable` objects to display.
        title : str, optional
            displayed at the top of the `Viewer` window
        figaspect : float, optional
            desired aspect ratio of figure. If arg is a number, use that aspect
            ratio. If arg is `auto`, the aspect ratio will be determined from
            the Variable's mesh.
        float xmin, xmax, ymin, ymax, datamin, 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*. All
            viewers will use *datamin* and *datamax*. Any limit set to a
            (default) value of `None` will autoscale.
        cmap : ~matplotlib.colors.Colormap, optional
            the :class:`~matplotlib.colors.Colormap`.
            Defaults to `matplotlib.cm.jet`
        colorbar : bool, optional
            plot a color bar in specified orientation if not `None`
        axes : ~matplotlib.axes.Axes, optional
            if not `None`, `vars` will be plotted into this Matplotlib `Axes` object
        log : bool, optional
          whether to logarithmically scale the data
        """
        if self.__class__ is AbstractMatplotlibViewer:
            raise NotImplementedError("can't instantiate abstract base class")

        AbstractViewer.__init__(self, vars=vars, title=title, **kwlimits)

        from matplotlib import pyplot as plt

        plt.ion()

        if axes is None:
            w, h = plt.figaspect(self.figaspect(figaspect, colorbar))
            self.fig = plt.figure(figsize=(w, h))
            self.axes = plt.gca()
        else:
            self.axes = axes
            self.fig = axes.get_figure()

        self.id = self.fig.number

        self.axes.set_title(self.title)

        self._mappable = None

        import matplotlib
        # Set the colormap and norm to correspond to the data for which
        # the colorbar will be used.
        if cmap is None:
            self.cmap = matplotlib.cm.jet
        else:
            self.cmap = cmap

        self.norm = None
        self.log = log

        if colorbar:
            self.colorbar = self.fig.colorbar(mappable=self.mappable,
                                              orientation=colorbar,
                                              label=self.vars[0].name)
        else:
            self.colorbar = None
Exemple #25
0
    def __init__(self, vars, title=None, daemon_file=None, fps=1.0, **kwlimits):
        """
        Create a `MayaviClient`.

        :Parameters:
          vars
            a `CellVariable` or tuple of `CellVariable` objects to plot
          title
            displayed at the top of the `Viewer` window
          xmin, xmax, ymin, ymax, zmin, zmax, datamin, datamax
            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
            the path to the script to run the separate Mayavi viewer process.
            Defaults to "fipy/viewers/mayaviViewer/mayaviDaemon.py"
          fps
            frames per second to attempt to display
        """
        self.fps = fps

        self.vtkdir = tempfile.mkdtemp()
        self.vtkcellfname = os.path.join(self.vtkdir, "cell.vtk")
        self.vtkfacefname = os.path.join(self.vtkdir, "face.vtk")
        self.vtklockfname = os.path.join(self.vtkdir, "lock")

        from fipy.viewers.vtkViewer import VTKCellViewer, VTKFaceViewer

        try:
            self.vtkCellViewer = VTKCellViewer(vars=vars)
            cell_vars = self.vtkCellViewer.vars
        except TypeError:
            self.vtkCellViewer = None
            cell_vars = []

        try:
            self.vtkFaceViewer = VTKFaceViewer(vars=vars)
            face_vars = self.vtkFaceViewer.vars
        except TypeError:
            self.vtkFaceViewer = None
            face_vars = []

        AbstractViewer.__init__(self, vars=cell_vars + face_vars, title=title, **kwlimits)

        self.plot()

        from pkg_resources import Requirement, resource_filename
        daemon_file = (daemon_file
                       or resource_filename(Requirement.parse("FiPy"),
                                            "fipy/viewers/mayaviViewer/mayaviDaemon.py"))

        cmd = ["python",
               daemon_file,
               "--lock",
               self.vtklockfname,
               "--fps",
               str(self.fps)]

        if self.vtkCellViewer is not None:
            cmd += ["--cell", self.vtkcellfname]

        if self.vtkFaceViewer is not None:
            cmd += ["--face", self.vtkfacefname]


        cmd += self._getLimit('xmin')
        cmd += self._getLimit('xmax')
        cmd += self._getLimit('ymin')
        cmd += self._getLimit('ymax')
        cmd += self._getLimit('zmin')
        cmd += self._getLimit('zmax')
        cmd += self._getLimit('datamin')
        cmd += self._getLimit('datamax')

        self.daemon = subprocess.Popen(cmd)