Esempio n. 1
0
def _plot_bc_helper(package, kper,
                    axes=None, names=None, filenames=None, fignum=None,
                    mflay=None, **kwargs):
    try:
        import matplotlib.pyplot as plt
    except:
        s = 'Could not import matplotlib.  Must install matplotlib ' +\
            ' in order to plot boundary condition data.'
        raise Exception(s)

    import flopy.plot.map as map

    # reshape 2d arrays to 3d for convenience
    ftype = package.name[0]

    nlay = package.parent.nlay

    # parse keyword arguments
    if 'figsize' in kwargs:
        figsize = kwargs.pop('figsize')
    else:
        figsize = None

    if 'inactive' in kwargs:
        inactive = kwargs.pop('inactive')
    else:
        inactive = True

    if 'grid' in kwargs:
        grid = kwargs.pop('grid')
    else:
        grid = False

    if 'dpi' in kwargs:
        dpi = kwargs.pop('dpi')
    else:
        dpi = None

    if 'masked_values' in kwargs:
        kwargs.pop('masked_values ')

    if mflay is not None:
        i0 = int(mflay)
        if i0+1 >= nlay:
            i0 = nlay - 1
        i1 = i0 + 1
    else:
        i0 = 0
        i1 = nlay

    if names is not None:
        if not isinstance(names, list):
            names = [names]
        assert len(names) == nlay

    if filenames is not None:
        if not isinstance(filenames, list):
            filenames = [filenames]
        assert len(filenames) == (i1 - i0)

    if fignum is not None:
        if not isinstance(fignum, list):
            fignum = [fignum]
        assert len(fignum) == (i1 - i0)
        # check for existing figures
        f0 = fignum[0]
        for i in plt.get_fignums():
            if i >= f0:
                f0 = i + 1
        finc = f0 - fignum[0]
        for idx in range(len(fignum)):
            fignum[idx] += finc
    else:
        #fignum = np.arange(i0, i1)
        # check for existing figures
        f0 = 0
        for i in plt.get_fignums():
            if i >= f0:
                f0 += 1
        f1 = f0 + (i1 - i0)
        fignum = np.arange(f0, f1)

    if axes is not None:
        if not isinstance(axes, list):
            axes = [axes]
        assert len(axes) == plotarray.shape[0]
    # prepare some axis objects for use
    else:
        axes = []
        for idx, k in enumerate(range(i0, i1)):
            fig = plt.figure(figsize=figsize, num=fignum[idx])
            ax = plt.subplot(1, 1, 1, aspect='equal')
            if names is not None:
                title = names[k]
            else:
                klay = k
                if mflay is not None:
                    klay = int(mflay)
                title = '{} Layer {}'.format('data', klay+1)
            ax.set_title(title)
            axes.append(ax)

    for idx, k in enumerate(range(i0, i1)):
        mm = map.ModelMap(ax=axes[idx], model=package.parent, layer=k)
        fig = plt.figure(num=fignum[idx])
        qm = mm.plot_bc(ftype=ftype, package=package, kper=kper, ax=axes[idx])

        if grid:
            mm.plot_grid(ax=axes[idx])

        if inactive:
            try:
                ib = package.parent.bas6.getibound()
                mm.plot_inactive(ibound=ib, ax=axes[idx])
            except:
                pass

    if len(axes) == 1:
        axes = axes[0]

    if filenames is not None:
        for idx, k in enumerate(range(i0, i1)):
            fig = plt.figure(num=fignum[idx])
            fig.savefig(filenames[idx], dpi=dpi)
            plt.close(fignum[idx])
            print('    created...{}'.format(os.path.basename(filenames[idx])))
        # there will be nothing to return when done
        axes = None
        plt.close('all')
    return axes
Esempio n. 2
0
def _plot_array_helper(plotarray, model=None, sr=None, axes=None,
                       names=None, filenames=None, fignum=None,
                       mflay=None, **kwargs):
    try:
        import matplotlib.pyplot as plt
    except:
        s = 'Could not import matplotlib.  Must install matplotlib ' +\
            ' in order to plot LayerFile data.'
        raise Exception(s)

    import flopy.plot.map as map
    

    # reshape 2d arrays to 3d for convenience
    if len(plotarray.shape) == 2:
        plotarray = plotarray.reshape((1, plotarray.shape[0],
                                       plotarray.shape[1]))

    # parse keyword arguments
    if 'figsize' in kwargs:
        figsize = kwargs.pop('figsize')
    else:
        figsize = None

    if 'masked_values' in kwargs:
        masked_values = kwargs.pop('masked_values')
    else:
        masked_values = None

    if 'pcolor' in kwargs:
        pcolor = kwargs.pop('pcolor')
    else:
        pcolor = True

    if 'inactive' in kwargs:
        inactive = kwargs.pop('inactive')
    else:
        inactive = True

    if 'contour' in kwargs:
        contourdata = kwargs.pop('contour')
    else:
        contourdata = False

    if 'clabel' in kwargs:
        clabel = kwargs.pop('clabel')
    else:
        clabel = False

    if 'colorbar' in kwargs:
        cb = kwargs.pop('colorbar')
    else:
        cb = False

    if 'grid' in kwargs:
        grid = kwargs.pop('grid')
    else:
        grid = False

    if 'levels' in kwargs:
        levels = kwargs.pop('levels')
    else:
        levels = None

    if 'colors' in kwargs:
        colors = kwargs.pop('colors')
    else:
        colors = 'black'
    
    if 'dpi' in kwargs:
        dpi = kwargs.pop('dpi')
    else:
        dpi = None
    
    if 'fmt' in kwargs:
        fmt = kwargs.pop('fmt')
    else:
        fmt = '%1.3f'
    
    if mflay is not None:
        i0 = int(mflay)
        if i0+1 >= plotarray.shape[0]:
            i0 = plotarray.shape[0] - 1
        i1 = i0 + 1
    else:
        i0 = 0
        i1 = plotarray.shape[0]
    
    if names is not None:
        if not isinstance(names, list):
            names = [names]
        assert len(names) == plotarray.shape[0]
    
    if filenames is not None:
        if not isinstance(filenames, list):
            filenames = [filenames]
        assert len(filenames) == (i1 - i0)
    
    if fignum is not None:
        if not isinstance(fignum, list):
            fignum = [fignum]
        assert len(fignum) == (i1 - i0)
        # check for existing figures
        f0 = fignum[0]
        for i in plt.get_fignums():
            if i >= f0:
                f0 = i + 1
        finc = f0 - fignum[0]
        for idx in range(len(fignum)):
            fignum[idx] += finc
    else:
        #fignum = np.arange(i0, i1)
        # check for existing figures
        f0 = 0
        for i in plt.get_fignums():
            if i >= f0:
                f0 += 1
        f1 = f0 + (i1 - i0)
        fignum = np.arange(f0, f1)


    if axes is not None:
        if not isinstance(axes, list):
            axes = [axes]
        assert len(axes) == plotarray.shape[0]
    # prepare some axis objects for use
    else:
        axes = []
        for idx, k in enumerate(range(i0, i1)):
            fig = plt.figure(figsize=figsize, num=fignum[idx])
            ax = plt.subplot(1, 1, 1, aspect='equal')
            if names is not None:
                title = names[k]
            else:
                klay = k
                if mflay is not None:
                    klay = int(mflay)
                title = '{} Layer {}'.format('data', klay+1)
            ax.set_title(title)
            axes.append(ax)
   
    for idx, k in enumerate(range(i0, i1)):
        fig = plt.figure(num=fignum[idx])
        mm = map.ModelMap(ax=axes[idx], model=model, sr=sr, layer=k)
        if pcolor:
            cm = mm.plot_array(plotarray[k], masked_values=masked_values,
                               ax=axes[idx], **kwargs)
            if cb:
                plt.colorbar(cm, ax=axes[idx], shrink=0.5)

        if contourdata:
            cl = mm.contour_array(plotarray[k], masked_values=masked_values,
                                  ax=axes[idx], colors=colors, levels=levels, **kwargs)
            if clabel:
                axes[idx].clabel(cl, fmt=fmt,**kwargs)

        if grid:
            mm.plot_grid(ax=axes[idx])

        if inactive:
            try:
                ib = model.bas6.getibound()
                mm.plot_inactive(ibound=ib, ax=axes[idx])
            except:
                pass

    if len(axes) == 1:
        axes = axes[0]
    if filenames is not None:
        for idx, k in enumerate(range(i0, i1)):
            fig = plt.figure(num=fignum[idx])
            fig.savefig(filenames[idx], dpi=dpi)
            print('    created...{}'.format(os.path.basename(filenames[idx])))
        # there will be nothing to return when done
        axes = None
        plt.close('all')
    return axes