예제 #1
0
파일: visualizers.py 프로젝트: pymor/pymor
    def visualize(self, U, m, title=None, legend=None, separate_colorbars=False,
                  rescale_colorbars=False, block=None, filename=None, columns=2):
        """Visualize the provided data.

        Parameters
        ----------
        U
            |VectorArray| of the data to visualize. If `len(U) > 1`, the data is visualized
            as a time series of plots. Alternatively, a tuple of |VectorArrays| can be
            provided, in which case a subplot is created for each entry of the tuple. The
            lengths of all arrays have to agree.
        m
            Filled in by :meth:`pymor.models.ModelBase.visualize` (ignored).
        title
            Title of the plot.
        legend
            Description of the data that is plotted. Most useful if `U` is a tuple in which
            case `legend` has to be a tuple of strings of the same length.
        separate_colorbars
            If `True`, use separate colorbars for each subplot.
        rescale_colorbars
            If `True`, rescale colorbars to data in each frame.
        block
            If `True`, block execution until the plot window is closed. If `None`, use the
            default provided during instantiation.
        filename
            If specified, write the data to a VTK-file using
            :func:`pymor.tools.vtkio.write_vtk` instead of displaying it.
        columns
            The number of columns in the visualizer GUI in case multiple plots are displayed
            at the same time.
        """
        assert isinstance(U, VectorArrayInterface) \
            or (isinstance(U, tuple)
                and all(isinstance(u, VectorArrayInterface) for u in U)
                and all(len(u) == len(U[0]) for u in U))
        if filename:
            if not isinstance(U, tuple):
                write_vtk(self.grid, U, filename, codim=self.codim)
            else:
                for i, u in enumerate(U):
                    write_vtk(self.grid, u, f'{filename}-{i}', codim=self.codim)
        else:
            if self.backend == 'jupyter':
                from pymor.gui.jupyter import visualize_patch
                visualize_patch(self.grid, U, bounding_box=self.bounding_box, codim=self.codim, title=title,
                                legend=legend, separate_colorbars=separate_colorbars,
                                rescale_colorbars=rescale_colorbars, columns=columns)
            else:
                block = self.block if block is None else block
                from pymor.gui.qt import visualize_patch
                visualize_patch(self.grid, U, bounding_box=self.bounding_box, codim=self.codim, title=title,
                                legend=legend, separate_colorbars=separate_colorbars,
                                rescale_colorbars=rescale_colorbars, backend=self.backend, block=block,
                                columns=columns)
예제 #2
0
    def visualize(self, U, m, title=None, legend=None, separate_colorbars=False,
                  rescale_colorbars=False, block=None, filename=None, columns=2):
        """Visualize the provided data.

        Parameters
        ----------
        U
            |VectorArray| of the data to visualize. If `len(U) > 1`, the data is visualized
            as a time series of plots. Alternatively, a tuple of |VectorArrays| can be
            provided, in which case a subplot is created for each entry of the tuple. The
            lengths of all arrays have to agree.
        m
            Filled in by :meth:`pymor.models.ModelBase.visualize` (ignored).
        title
            Title of the plot.
        legend
            Description of the data that is plotted. Most useful if `U` is a tuple in which
            case `legend` has to be a tuple of strings of the same length.
        separate_colorbars
            If `True`, use separate colorbars for each subplot.
        rescale_colorbars
            If `True`, rescale colorbars to data in each frame.
        block
            If `True`, block execution until the plot window is closed. If `None`, use the
            default provided during instantiation.
        filename
            If specified, write the data to a VTK-file using
            :func:`pymor.tools.vtkio.write_vtk` instead of displaying it.
        columns
            The number of columns in the visualizer GUI in case multiple plots are displayed
            at the same time.
        """
        assert isinstance(U, VectorArrayInterface) \
            or (isinstance(U, tuple)
                and all(isinstance(u, VectorArrayInterface) for u in U)
                and all(len(u) == len(U[0]) for u in U))
        if filename:
            if not isinstance(U, tuple):
                write_vtk(self.grid, U, filename, codim=self.codim)
            else:
                for i, u in enumerate(U):
                    write_vtk(self.grid, u, f'{filename}-{i}', codim=self.codim)
        else:
            if self.backend == 'jupyter':
                from pymor.gui.jupyter import visualize_patch
                visualize_patch(self.grid, U, bounding_box=self.bounding_box, codim=self.codim, title=title,
                                legend=legend, separate_colorbars=separate_colorbars,
                                rescale_colorbars=rescale_colorbars, columns=columns)
            else:
                block = self.block if block is None else block
                from pymor.gui.qt import visualize_patch
                visualize_patch(self.grid, U, bounding_box=self.bounding_box, codim=self.codim, title=title,
                                legend=legend, separate_colorbars=separate_colorbars,
                                rescale_colorbars=rescale_colorbars, backend=self.backend, block=block,
                                columns=columns)
예제 #3
0
def test_vtkio(rect_or_tria_grid):
    grid = rect_or_tria_grid
    steps = 4
    for dim in range(1, 2):
        for codim, data in enumerate((NumpyVectorSpace.from_data(np.zeros((steps, grid.size(c)))) for c in range(grid.dim+1))):
            with SafeTemporaryFileName('wb') as out_name:
                if codim == 1:
                    with pytest.raises(NotImplementedError):
                        write_vtk(grid, data, out_name, codim=codim)
                else:
                    write_vtk(grid, data, out_name, codim=codim)
예제 #4
0
파일: tools.py 프로젝트: lucas-ca/pymor
def test_vtkio(rect_or_tria_grid):
    grid = rect_or_tria_grid
    steps = 4
    for dim in range(1, 2):
        for codim, data in enumerate((NumpyVectorArray(np.zeros((steps, grid.size(c)))) for c in range(grid.dim+1))):
            with NamedTemporaryFile('wb') as out:
                if codim == 1:
                    with pytest.raises(NotImplementedError):
                        write_vtk(grid, data, out.name, codim=codim)
                else:
                    write_vtk(grid, data, out.name, codim=codim)
예제 #5
0
파일: qt.py 프로젝트: renemilk/pyMor
 def save(self):
     if not config.HAVE_PYVTK:
         msg = QMessageBox(QMessageBox.Critical, 'Error', 'VTK output disabled. Pleas install pyvtk.')
         msg.exec_()
         return
     filename = QFileDialog.getSaveFileName(self, 'Save as vtk file')[0]
     base_name = filename.split('.vtu')[0].split('.vtk')[0].split('.pvd')[0]
     if base_name:
         if len(self.U) == 1:
             write_vtk(self.grid, NumpyVectorSpace.make_array(self.U[0]), base_name, codim=self.codim)
         else:
             for i, u in enumerate(self.U):
                 write_vtk(self.grid, NumpyVectorSpace.make_array(u), '{}-{}'.format(base_name, i),
                           codim=self.codim)
예제 #6
0
파일: qt.py 프로젝트: luca-heltai/pymor
    def visualize(self, U, discretization, title=None, legend=None, separate_colorbars=False,
                  block=None, filename=None):
        '''Visualize the provided data.

        Parameters
        ----------
        U
            |VectorArray| of the data to visualize. If `len(U) > 1`, the data is visualized
            as a time series of plots. Alternatively, a tuple of |VectorArrays| can be
            provided, in which case a subplot is created for each entry of the tuple. The
            lengths of all arrays have to agree.
        discretization
            Filled in :meth:`pymor.discretizations.DiscretizationBase.visualize` (ignored).
        title
            Title of the plot.
        legend
            Description of the data that is plotted. Most useful if `U` is a tuple in which
            case `legend` has to be a tuple of strings of the same length.
        separate_colorbars
            If `True` use separate colorbars for each subplot.
        block
            If `True` block execution until the plot window is closed. If `None`, use the
            default provided during instantiation.
        filename
            If specified, write the data to a VTK-file using
            :func:`pymor.tools.vtkio.write_vtk` instead of displaying it.
        '''
        assert isinstance(U, VectorArrayInterface) and hasattr(U, 'data') \
            or (isinstance(U, tuple) and all(isinstance(u, VectorArrayInterface) and hasattr(u, 'data') for u in U)
                and all(len(u) == len(U[0]) for u in U))
        if filename:
            if not isinstance(U, tuple):
                write_vtk(self.grid, U, filename, codim=self.codim)
            else:
                for i, u in enumerate(self.U):
                    write_vtk(self.grid, u, '{}-{}'.format(filename, i), codim=self.codim)
        else:
            block = self.block if block is None else block
            visualize_patch(self.grid, U, bounding_box=self.bounding_box, codim=self.codim, title=title,
                            legend=legend, separate_colorbars=separate_colorbars, backend=self.backend,
                            block=block)
예제 #7
0
 def save(self):
     if not config.HAVE_PYVTK:
         msg = QMessageBox(QMessageBox.Critical, 'Error',
                           'VTK output disabled. Pleas install pyvtk.')
         msg.exec_()
         return
     filename = QFileDialog.getSaveFileName(self, 'Save as vtk file')[0]
     base_name = filename.split('.vtu')[0].split('.vtk')[0].split(
         '.pvd')[0]
     if base_name:
         if len(self.U) == 1:
             write_vtk(self.grid,
                       NumpyVectorSpace.make_array(self.U[0]),
                       base_name,
                       codim=self.codim)
         else:
             for i, u in enumerate(self.U):
                 write_vtk(self.grid,
                           NumpyVectorSpace.make_array(u),
                           '{}-{}'.format(base_name, i),
                           codim=self.codim)