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" _Viewer.__init__(self, vars=vars, title=title, **kwlimits) self.mesh = self.vars[0].getMesh() self.id = _GistViewer._id _GistViewer._id += 1 import gist gist.window(self.id, wait = 1, dpi = dpi, display = '')
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) _Viewer.__init__(self, vars=vars, title=title, **kwlimits) mesh = self.vars[0].getMesh() self.dataset = self._makeDataSet(mesh) data = self._getData() 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)
def __init__(self, vars, title=None, figaspect=1.0, **kwlimits): """ Create a `_MatplotlibViewer`. :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. """ if self.__class__ is _MatplotlibViewer: raise NotImplementedError, "can't instantiate abstract base class" _Viewer.__init__(self, vars=vars, title=title, **kwlimits) import pylab pylab.ion() w, h = pylab.figaspect(figaspect) fig = pylab.figure(figsize=(w, h)) self.id = fig.number pylab.title(self.title)
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) _Viewer.__init__(self, vars=vars, title=title, **kwlimits) mesh = self.vars[0].getMesh() for var in self.vars: assert mesh is var.getMesh()
def __init__(self, vars, title=None, figaspect=1.0, cmap=None, colorbar=None, axes=None, **kwlimits): """ Create a `_MatplotlibViewer`. :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 """ if self.__class__ is _MatplotlibViewer: raise NotImplementedError, "can't instantiate abstract base class" _Viewer.__init__(self, vars=vars, title=title, **kwlimits) import pylab pylab.ion() if axes is None: w, h = pylab.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
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" _Viewer.__init__(self, vars=vars, title=title, **kwlimits) import Gnuplot self.g = Gnuplot.Gnuplot() self.g('set title "' + self.title + '"')
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.getVars() except TypeError: self.vtkCellViewer = None cell_vars = [] try: self.vtkFaceViewer = VTKFaceViewer(vars=vars) face_vars = self.vtkFaceViewer.getVars() except TypeError: self.vtkFaceViewer = None face_vars = [] _Viewer.__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 __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.getCellCenters() >>> 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) _Viewer.__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.getMesh().getDim() != 2: raise 'The MayaviIsoViewer only works for 2D meshes.'