Example #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
Example #2
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'])
Example #3
0
def showMesh(mesh, data=None, showLater=False, colorBar=False, axes=None,
             *args, **kwargs):
    """
    Syntactic sugar, short-cut to create axes and plot node or cell values
    return axes, cbar

    Parameters
    ----------
    """

    ret = []

    ax = axes
    
    if ax == None:
        fig = plt.figure()
        ax = fig.add_subplot(1,1,1)
        
    gci = None
    cbar = None
    validData = False

    if data is None:
        drawMesh(ax, mesh)
    else:
        #print(data[0], type(data[0]))
        if hasattr(data[0], '__len__') and type(data) != np.ma.core.MaskedArray:
            if sum(data[:,0]) != sum(data[:,1]):
                drawStreamLines2(ax, mesh, data, *args, **kwargs)
            else:
                print("No valid stream data:",  data)
                drawMesh(ax, mesh)

        elif min(data) == max(data):
            print(("No valid data",  min(data), max(data)))
            drawMesh(ax, mesh)
        else:
            validData = True
            if len(data) == mesh.cellCount():
                gci = drawModel(ax, mesh, data, *args, **kwargs)
            elif len(data) == mesh.nodeCount():
                gci = drawField(ax, mesh, data, *args, **kwargs)

    ax.set_aspect('equal')

    if colorBar and validData:
        cbar = createColorbar(gci, *args, **kwargs)

    if not showLater:
        plt.show()

    #fig.show()
    #fig.canvas.draw()
    return ax, cbar
Example #4
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
Example #5
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"])
Example #6
0
def showMesh(mesh, data=None, hold=False, block=False,
             colorBar=False, coverage=None,
             axes=None, savefig=None, **kwargs):
    """
    2D Mesh visualization.

    Create an axes and plot node or cell values for the given 2d mesh.
    Returns the axes and the color bar.

    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.meshview.drawMesh`

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

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

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

        . pg.stdVectorRVector3 -- sensor positions
            forward to :py:mod:`pygimli.mplviewer.meshview.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 [false]
        Create and show a colorbar.

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

    axes : matplotlib.Axes [None]
        Instead of create a new and empty axes, 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 :
        Will be forwarded to the draw functions and matplotlib methods,
        respectively.

    Returns
    -------
    axes : matplotlib.axes

    colobar : matplotlib.colobar
    """

    ax = axes
    if block:
        hold = 1

    if hold:
        lastHoldStatus = pg.mplviewer.holdAxes_
        pg.mplviewer.holdAxes_ = 1

    if ax is None:
        fig, ax = plt.subplots()

    gci = None
    cbar = None
    validData = False

    if data is None:
        drawMesh(ax, mesh)
    elif isinstance(data, pg.stdVectorRVector3):
        drawSensors(ax, data)
    else:
        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)

        elif (min(data) == max(data)):  # or pg.haveInfNaN(data):

            print("No valid data: ", min(data), max(data), pg.haveInfNaN(data))
            drawMesh(ax, mesh)
        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)
            except Exception as e:
                print("Exception occured: " + e)
                print("Data: ", min(data), max(data), pg.haveInfNaN(data))
                print("Mesh: ", mesh)
                drawMesh(ax, mesh)

    ax.set_aspect('equal')

    label = kwargs.pop('label', None)

    if colorBar and validData:
        # , *args, **kwargs) # causes problems!
        cbar = createColorbar(gci, label=label, **kwargs)

    plt.tight_layout()

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

    if showLater in kwargs:
        hold = showLater
        print("showLater will be removed in the future. use hold instead")

    if not hold or block is not False:
        plt.show(block=block)
        try:
            plt.pause(0.01)
        except:
            pass

    if hold:
        pg.mplviewer.holdAxes_ = lastHoldStatus

    if savefig:
        print('saving: ' + savefig + ' ...')
        ax.figure.savefig(savefig, bbox_inches='tight')

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

    return ax, cbar