Beispiel #1
0
    def showResult(self, val=None, ax=None, cMin=None, cMax=None,
                   logScale=False, name='result', **kwargs):
        """show resulting velocity vector"""
        mesh = self.paraDomain()
        if val is None:
            val = self.velocity
        if cMin is None or cMax is None:
            cMin, cMax = interperc(val, 3)
        if ax is None:
            fig, ax = plt.subplots()
            self.figs[name] = fig
            ax, cbar = pg.show(mesh, val, logScale=logScale, axes=ax,
                               colorBar=True, cMin=cMin, cMax=cMax,
                               coverage=self.standardizedCoverage(), **kwargs)
            self.figs[name] = plt.gcf()
        else:
            gci = drawModel(ax, mesh, val, logScale=logScale,
                            colorBar=True, cMin=cMin, cMax=cMax,
                            coverage=self.standardizedCoverage(), **kwargs)
            labels = ['cMin', 'cMax', 'nLevs', 'orientation', 'label']
            subkwargs = {key: kwargs[key] for key in labels if key in kwargs}
            cbar = createColorbar(gci, **subkwargs)
        browser = CellBrowser(self.mesh, val, ax)
        browser.connect()

        self.axs[name] = ax
        if 'lines' in kwargs:
            plotLines(ax, kwargs['lines'])
        return ax, cbar
Beispiel #2
0
    def showResult(self,
                   val=None,
                   ax=None,
                   cMin=None,
                   cMax=None,
                   logScale=False,
                   name='result',
                   **kwargs):
        """show resulting velocity vector"""
        mesh = self.paraDomain()
        if val is None:
            val = self.velocity
        if cMin is None or cMax is None:
            cMin, cMax = interperc(val, 3)
        if ax is None:
            fig, ax = plt.subplots()
            self.figs[name] = fig
            ax, cbar = pg.show(mesh,
                               val,
                               logScale=logScale,
                               ax=ax,
                               colorBar=True,
                               cMin=cMin,
                               cMax=cMax,
                               coverage=self.standardizedCoverage(),
                               **kwargs)
            self.figs[name] = plt.gcf()
        else:
            gci = drawModel(ax,
                            mesh,
                            val,
                            logScale=logScale,
                            colorBar=True,
                            cMin=cMin,
                            cMax=cMax,
                            coverage=self.standardizedCoverage(),
                            **kwargs)
            labels = ['cMin', 'cMax', 'nLevs', 'orientation', 'label']
            subkwargs = {key: kwargs[key] for key in labels if key in kwargs}
            cbar = createColorbar(gci, **subkwargs)
        browser = CellBrowser(self.mesh, val, ax)
        browser.connect()

        self.axs[name] = ax
        if 'lines' in kwargs:
            plotLines(ax, kwargs['lines'])
        return ax, cbar
Beispiel #3
0
    def showResult(self, ax=None, cMin=None, cMax=None, logScale=False,
                   **kwargs):
        """show resulting velocity vector"""
        if cMin is None or cMax is None:
            cMin, cMax = interperc(self.velocity, 3)
        if ax is None:
            ax, cbar = pg.show(self.mesh, self.velocity, logScale=logScale,
                               colorBar=True, cMin=cMin, cMax=cMax, **kwargs)
            self.figs['result'] = plt.gcf()
        else:
            gci = drawModel(ax, self.mesh, self.velocity, logScale=logScale,
                            colorBar=True, cMin=cMin, cMax=cMax, **kwargs)
            createColorbar(gci, **kwargs)
        browser = CellBrowser(self.mesh, self.velocity, ax)
        browser.connect()

        self.axs['result'] = ax
        if 'lines' in kwargs:
            plotLines(ax, kwargs['lines'])
Beispiel #4
0
    def showResult(self, ax=None, cMin=None, cMax=None, logScale=False, **kwargs):
        """show resulting velocity vector"""
        if cMin is None or cMax is None:
            cMin, cMax = interperc(self.velocity, 3)
        if ax is None:
            ax, cbar = pg.show(
                self.mesh, self.velocity, logScale=logScale, colorBar=True, cMin=cMin, cMax=cMax, **kwargs
            )
            fig, ax = plt.subplots()
            self.figs["result"] = fig
        else:
            gci = drawModel(
                ax, self.mesh, self.velocity, logScale=logScale, colorBar=True, cMin=cMin, cMax=cMax, **kwargs
            )
            cbar = createColorbar(gci, **kwargs)
            browser = CellBrowser(self.mesh, self.velocity, ax)
            browser.connect()
            plt.show()  # block=False)

        self.axs["result"] = ax
        if "lines" in kwargs:
            plotLines(ax, kwargs["lines"])
Beispiel #5
0
    def showResult(self,
                   val=None,
                   ax=None,
                   cMin=None,
                   cMax=None,
                   logScale=False,
                   rays=False,
                   name='result',
                   **kwargs):
        """Show resulting velocity vector.

        Parameters
        ----------
        val : result array [self.velocity]
            field to show, usually the velocity vector
        ax : matplotlib.axes
            axes to plot into, if not give a new one-axis figure is created
        cMin/cMax : float
            minimum and maximum values for ranging colorbar
        logScale : bool [False]
            use logarithmic scale
        rays : bool [False]
            Show ray paths as well.

        Other parameters
        ----------------
        useCoverage : bool [True]
            use standardized (0 or 1) ray coverage as alpha-shading
        label : str
            label to write on colorbar
        orientaton : str
            color bar orientation
        nLevs : int [7]
            number of level values for color bar
        **kwargs : keyword arguments passed to the show function

        Returns
        -------
        ax : maxplotlib axes

        cb : matplotlib color bar object
        """
        mesh = self.paraDomain()
        if val is None:
            val = self.velocity
        if cMin is None or cMax is None:
            cMin, cMax = interperc(val, 3)
        coverage = 1
        if kwargs.pop('useCoverage', True):
            coverage = self.standardizedCoverage()
        label = kwargs.pop("label", "Velocity (m/s)")
        if ax is None:
            fig, ax = plt.subplots()
            self.figs[name] = fig
            ax, cbar = pg.show(mesh,
                               val,
                               logScale=logScale,
                               ax=ax,
                               colorBar=True,
                               cMin=cMin,
                               cMax=cMax,
                               coverage=coverage,
                               label=label,
                               hold=True,
                               **kwargs)
            self.figs[name] = plt.gcf()
        else:
            gci = drawModel(ax,
                            mesh,
                            val,
                            logScale=logScale,
                            colorBar=True,
                            cMin=cMin,
                            cMax=cMax,
                            coverage=coverage,
                            **kwargs)
            labels = ['cMin', 'cMax', 'nLevs', 'orientation']
            subkwargs = {key: kwargs[key] for key in labels if key in kwargs}
            cbar = createColorBar(gci, label=label, **subkwargs)
        if rays:
            self.showRayPaths(ax=ax, alpha=0.5, color="w", linewidths=.8)

        browser = CellBrowser(self.mesh, val, ax)
        browser.connect()

        self.axs[name] = ax
        if 'lines' in kwargs:
            plotLines(ax, kwargs['lines'])
        return ax, cbar
Beispiel #6
0
def showMesh(mesh,
             data=None,
             hold=False,
             block=False,
             colorBar=None,
             label=None,
             coverage=None,
             ax=None,
             savefig=None,
             **kwargs):
    """2D Mesh visualization.

    Create an axis object and plot a 2D mesh with given node or cell data.
    Returns the axis and the color bar. The type of data determine the
    appropriate draw method.

    Parameters
    ----------

    mesh : :gimliapi:`GIMLI::Mesh`
        2D or 3D GIMLi mesh

    data : iterable [None]
        Optionally data to visualize.

        . None (draw mesh only)
            forward to :py:mod:`pygimli.mplviewer.drawMesh`
            or if no cells are given:
            forward to :py:mod:`pygimli.mplviewer.drawPLC`

        . float per cell -- model, patch
            forward to :py:mod:`pygimli.mplviewer.drawModel`

        . float per node -- scalar field
            forward to :py:mod:`pygimli.mplviewer.drawField`

        . iterable of type [float, float] -- vector field
            forward to :py:mod:`pygimli.mplviewer.drawStreams`

        . pg.stdVectorRVector3 -- sensor positions
            forward to :py:mod:`pygimli.mplviewer.drawSensors`

    hold : bool [false]
        Set interactive plot mode for matplotlib.
        If this is set to false [default] your script will open
        a window with the figure and draw your content.
        If set to true nothing happens until you either force another show with
        hold=False, you call plt.show() or pg.wait().
        If you want show with stopping your script set block = True.

    block : bool [false]
        Force show drawing your content and block the script until you
        close the current figure.

    colorBar : bool [None], Colorbar
        Create and show a colorbar. If colorBar is a valid colorbar then only
        his values will be updated.

    label : str
        Set colorbar label. If set colorbar is toggled to True. [None]

    coverage : iterable [None]
        Weight data by the given coverage array and fadeout the color.

    ax : matplotlib.Axes [None]
        Instead of create a new and empty ax, just draw into the a given.
        Useful to combine draws.

    savefig: string
        Filename for a direct save to disc.
        The matplotlib pdf-output is a little bit big so we try
        an epstopdf if the .eps suffix is found in savefig

    **kwargs :
        * xlabel : str [None]
            Add label to the x axis

        * ylabel : str [None]
            Add label to the y axis

        * all remaining
            Will be forwarded to the draw functions and matplotlib methods,
            respectively.

    Returns
    -------
    ax : matplotlib.ax

    colobar : matplotlib.colobar
    """
    ax = ax
    if block:
        hold = 1

    if hold:
        lastHoldStatus = pg.mplviewer.utils.holdAxes__
        pg.mplviewer.hold(val=1)

    # print('1*'*50)
    # print(locale.localeconv())

    if ax is None:
        ax = plt.subplots()[1]

    # plt.subplots() resets locale setting to system default .. this went
    # horrible wrong for german 'decimal_point': ','
    pg.checkAndFixLocaleDecimal_point(verbose=False)

    # print('2*'*50)
    # print(locale.localeconv())

    gci = None
    validData = False

    if data is None:
        drawMesh(ax, mesh, **kwargs)
    elif isinstance(data, pg.stdVectorRVector3):
        drawSensors(ax, data, **kwargs)
    else:
        # print(data, type(data))
        if (hasattr(data[0], '__len__')
                and not isinstance(data, np.ma.core.MaskedArray)):

            if len(data) == 2:  # [u,v]
                data = np.array(data).T

            if sum(data[:, 0]) != sum(data[:, 1]):
                drawStreams(ax, mesh, data, **kwargs)
            else:
                print("No valid stream data:", data)
                drawMesh(ax, mesh, **kwargs)
        elif min(data) == max(data):  # or pg.haveInfNaN(data):
            print("No valid data: ", min(data), max(data), pg.haveInfNaN(data))
            drawMesh(ax, mesh, **kwargs)
        else:
            validData = True
            try:
                if len(data) == mesh.cellCount():
                    gci = drawModel(ax, mesh, data, **kwargs)
                elif len(data) == mesh.nodeCount():
                    gci = drawField(ax, mesh, data, **kwargs)

                cmap = kwargs.pop('cmap', None)
                cMap = kwargs.pop('cMap', None)
                if cMap is not None:
                    cmap = cMap

                if cmap is not None:
                    gci.set_cmap(cmapFromName(cmap))

            except BaseException as e:
                print("Exception occured: " + e)
                print("Data: ", min(data), max(data), pg.haveInfNaN(data))
                print("Mesh: ", mesh)
                drawMesh(ax, mesh, **kwargs)

    ax.set_aspect('equal')

    cbar = None

    if label is not None and colorBar is None:
        colorBar = True

    if colorBar and validData:
        # , **kwargs) # causes problems!
        labels = ['cMin', 'cMax', 'nLevs', 'orientation', 'pad']
        subkwargs = {key: kwargs[key] for key in labels if key in kwargs}

        if colorBar is True or colorBar is 1:
            cbar = createColorBar(gci, label=label, **subkwargs)
        elif colorBar is not False:
            cbar = updateColorBar(colorBar, gci, label=label, **subkwargs)

    if coverage is not None:
        if len(data) == mesh.cellCount():
            addCoverageAlpha(gci, coverage)
        else:
            raise BaseException('toImplement')
            # addCoverageAlpha(gci, pg.cellDataToPointData(mesh, coverage))

    if not hold or block is not False:
        if data is not None:
            if len(data) == mesh.cellCount():
                cb = CellBrowser(mesh, data, ax=ax)
                cb.connect()

        plt.show(block=block)
        try:
            plt.pause(0.01)
        except BaseException as _:

            pass

    if hold:
        pg.mplviewer.hold(val=lastHoldStatus)

    if savefig:
        print('saving: ' + savefig + ' ...')

        if '.' not in savefig:
            savefig += '.pdf'

        ax.figure.savefig(savefig, bbox_inches='tight')
        # rc params savefig.format=pdf

        if '.eps' in savefig:
            try:
                print("trying eps2pdf ... ")
                os.system('epstopdf ' + savefig)
            except BaseException as _:
                pass
        print('..done')

    return ax, cbar
Beispiel #7
0
    def showResult(self, val=None, ax=None, cMin=None, cMax=None,
                   logScale=False, rays=False, name='result', **kwargs):
        """Show resulting velocity vector.

        Parameters
        ----------
        val : result array [self.velocity]
            field to show, usually the velocity vector
        ax : matplotlib.axes
            axes to plot into, if not give a new one-axis figure is created
        cMin/cMax : float
            minimum and maximum values for ranging colorbar
        logScale : bool [False]
            use logarithmic scale
        rays : bool [False]
            Show ray paths as well.

        Other parameters
        ----------------
        useCoverage : bool [True]
            use standardized (0 or 1) ray coverage as alpha-shading
        label : str
            label to write on colorbar
        orientaton : str
            color bar orientation
        nLevs : int [7]
            number of level values for color bar
        **kwargs : keyword arguments passed to the show function

        Returns
        -------
        ax : maxplotlib axes

        cb : matplotlib color bar object
        """
        mesh = self.paraDomain()
        if val is None:
            val = self.velocity
        if cMin is None or cMax is None:
            cMin, cMax = interperc(val, 3)
        coverage = 1
        if kwargs.pop('useCoverage', True):
            coverage = self.standardizedCoverage()
        label = kwargs.pop("label", "Velocity (m/s)")
        if ax is None:
            fig, ax = plt.subplots()
            self.figs[name] = fig
            ax, cbar = pg.show(mesh, val, logScale=logScale, ax=ax,
                               colorBar=True, cMin=cMin, cMax=cMax,
                               coverage=coverage, label=label, hold=True,
                               **kwargs)
            self.figs[name] = plt.gcf()
        else:
            gci = drawModel(ax, mesh, val, logScale=logScale,
                            colorBar=True, cMin=cMin, cMax=cMax,
                            coverage=coverage, **kwargs)
            labels = ['cMin', 'cMax', 'nLevs', 'orientation']
            subkwargs = {key: kwargs[key] for key in labels if key in kwargs}
            cbar = createColorBar(gci, label=label, **subkwargs)
        if rays:
            self.showRayPaths(ax=ax, alpha=0.5, color="w", linewidths=.8)

        browser = CellBrowser(self.mesh, val, ax)
        browser.connect()

        self.axs[name] = ax
        if 'lines' in kwargs:
            plotLines(ax, kwargs['lines'])
        return ax, cbar