Esempio n. 1
0
def plot_ts(sim):
    fs = USGSFigure(figure_type="graph", verbose=False)
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)
    ylabel = ["head (m)", "flow ($m^3/d$", "flow ($m^3/d$"]
    for iplot, obstype in enumerate(["obs.head", "obs.flow", "ghb.obs"]):
        fig = plt.figure(figsize=(6, 3))
        ax = fig.add_subplot()
        fname = os.path.join(sim_ws, "{}.{}.csv".format(sim_name, obstype))
        tsdata = np.genfromtxt(fname, names=True, delimiter=",")
        for name in tsdata.dtype.names[1:]:
            ax.plot(tsdata["time"], tsdata[name], label=name)
        ax.set_xlabel("time (d)")
        ax.set_ylabel(ylabel[iplot])
        fs.graph_legend(ax)
        if config.plotSave:
            fpth = os.path.join(
                "..",
                "figures",
                "{}-{}{}".format(
                    sim_name, obstype.replace(".", "-"), config.figure_ext
                ),
            )
            fig.savefig(fpth)
    return
def plot_ts(sim):
    fs = USGSFigure(figure_type="graph", verbose=False)
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)
    obsnames = gwf.obs[1].output.obs_names
    obs_list = [
        gwf.obs[1].output.obs(f=obsnames[0]),
        gwf.obs[1].output.obs(f=obsnames[1]),
        gwf.ghb.output.obs(),
    ]
    ylabel = ("head (m)", "flow ($m^3/d$)", "flow ($m^3/d$)")
    obs_fig = ("obs-head", "obs-flow", "ghb-obs")
    for iplot, obstype in enumerate(obs_list):
        fig = plt.figure(figsize=(6, 3))
        ax = fig.add_subplot()
        tsdata = obstype.data
        for name in tsdata.dtype.names[1:]:
            ax.plot(tsdata["totim"], tsdata[name], label=name)
        ax.set_xlabel("time (d)")
        ax.set_ylabel(ylabel[iplot])
        fs.graph_legend(ax)
        if config.plotSave:
            fpth = os.path.join(
                "..",
                "figures",
                "{}-{}{}".format(sim_name, obs_fig[iplot], config.figure_ext),
            )
            fig.savefig(fpth)
    return
def plot_results(mt3d, mf6, idx, ax=None):
    if config.plotModel:
        mt3d_out_path = mt3d.model_ws
        mf6_out_path = mf6.simulation_data.mfpath.get_sim_path()
        mf6.simulation_data.mfpath.get_sim_path()

        # Get the MT3DMS concentration output
        fname_mt3d = os.path.join(mt3d_out_path, "MT3D001.UCN")
        ucnobj_mt3d = flopy.utils.UcnFile(fname_mt3d)
        conc_mt3d = ucnobj_mt3d.get_alldata()

        # Get the MF6 concentration output
        gwt = mf6.get_model(list(mf6.model_names)[1])
        ucnobj_mf6 = gwt.output.concentration()
        conc_mf6 = ucnobj_mf6.get_alldata()

        # Create figure for scenario
        fs = USGSFigure(figure_type="graph", verbose=False)
        sim_name = mf6.name
        if ax is None:
            fig, ax = plt.subplots(1,
                                   1,
                                   figsize=figure_size,
                                   dpi=300,
                                   tight_layout=True)

        ax.plot(
            np.linspace(0, l, ncol),
            conc_mt3d[0, 0, 0, :],
            color="k",
            label="MT3DMS",
            linewidth=0.5,
        )
        ax.plot(
            np.linspace(0, l, ncol),
            conc_mf6[0, 0, 0, :],
            "^",
            markeredgewidth=0.5,
            color="blue",
            fillstyle="none",
            label="MF6",
            markersize=3,
        )
        ax.set_ylim(0, 1.2)
        ax.set_xlim(0, 1000)
        ax.set_xlabel("Distance, in m")
        ax.set_ylabel("Concentration")
        title = "Concentration Profile at Time = 2,000 " + "{}".format(
            time_units)
        ax.legend()
        letter = chr(ord("@") + idx + 1)
        fs.heading(letter=letter, heading=title)

        # save figure
        if config.plotSave:
            fpth = os.path.join("..", "figures",
                                "{}{}".format(sim_name, config.figure_ext))
            fig.savefig(fpth)
def plot_results(mt3d, mf6, idx, leglab1, leglab2, ax=None):
    if config.plotModel:
        mt3d_out_path = mt3d.model_ws
        mf6_out_path = mf6.simulation_data.mfpath.get_sim_path()
        mf6.simulation_data.mfpath.get_sim_path()

        # Get the MT3DMS concentration output
        fname_mt3d = os.path.join(mt3d_out_path, "MT3D001.UCN")
        ucnobj_mt3d = flopy.utils.UcnFile(fname_mt3d)
        conc_mt3d = ucnobj_mt3d.get_alldata()

        # Get the MF6 concentration output
        gwt = mf6.get_model(list(mf6.model_names)[1])
        ucnobj_mf6 = gwt.output.concentration()
        conc_mf6 = ucnobj_mf6.get_alldata()

        # Create figure for scenario
        fs = USGSFigure(figure_type="graph", verbose=False)
        sim_name = mf6.name
        plt.rcParams["lines.dashed_pattern"] = [5.0, 5.0]
        if ax is None:
            fig = plt.figure(figsize=figure_size, dpi=300, tight_layout=True)
            ax = fig.add_subplot(1, 1, 1, aspect="equal")

        x = mt3d.modelgrid.xcellcenters
        y = mt3d.modelgrid.ycellcenters

        levels = [0.15, 1.0, 2.0, 5.0]
        mm = flopy.plot.PlotMapView(model=mt3d)

        cf = plt.contourf(
            x, y, conc_mt3d[0, 0, :, :], levels=levels, alpha=0.5
        )
        cbar = plt.colorbar(cf, shrink=0.25)
        cbar.ax.set_title(leglab1)

        cs2 = mm.contour_array(
            conc_mf6[0, 0, :, :], levels=levels, colors="r", linestyles="--"
        )
        plt.clabel(cs2)
        labels = [leglab2]
        for i in range(len(labels)):
            cs2.collections[i].set_label(labels[i])
        plt.legend(loc="upper left")

        plt.xlabel("Distance Along X-Axis, in meters")
        plt.ylabel("Distance Along Y-Axis, in meters")
        title = "MT3DMS-MF6 Comparison"

        letter = chr(ord("@") + idx + 1)
        fs.heading(letter=letter, heading=title)

        # save figure
        if config.plotSave:
            fpth = os.path.join(
                "..", "figures", "{}{}".format(sim_name, config.figure_ext)
            )
            fig.savefig(fpth)
def plot_gwf_results(sims):
    if config.plotModel:
        print("Plotting model results...")
        sim_mf6gwf, sim_mf6gwt = sims
        gwf = sim_mf6gwf.flow
        fs = USGSFigure(figure_type="map", verbose=False)

        sim_ws = sim_mf6gwf.simulation_data.mfpath.get_sim_path()

        fname = os.path.join(sim_ws, "flow.hds")
        head = flopy.utils.HeadFile(fname, text="head", precision="double")
        head = head.get_data()

        fname = os.path.join(sim_ws, "flow.lak.bin")
        stage = flopy.utils.HeadFile(fname, text="stage", precision="double")
        stage = stage.get_data().flatten()
        il, jl = np.where(lakibd > 0)
        for i, j in zip(il, jl):
            ilak = lakibd[i, j] - 1
            lake_stage = stage[ilak]
            head[0, i, j] = lake_stage

        fig, axs = plt.subplots(1,
                                2,
                                figsize=figure_size,
                                dpi=300,
                                tight_layout=True)

        for ilay in [0, 1]:
            ax = axs[ilay]
            pmv = plot_bcmap(ax, gwf, ilay)
            levels = np.arange(20, 60, 1)
            cs = pmv.contour_array(
                head,
                colors="blue",
                linestyles="-",
                levels=levels,
                masked_values=[1.0e30],
            )
            ax.clabel(cs, cs.levels[::5], fmt="%1.0f", colors="b")
            title = "Model Layer {}".format(ilay + 1)
            letter = chr(ord("@") + ilay + 1)
            fs.heading(letter=letter, heading=title, ax=ax)

        # save figure
        if config.plotSave:
            sim_folder = os.path.split(sim_ws)[0]
            sim_folder = os.path.basename(sim_folder)
            fname = "{}-head{}".format(sim_folder, config.figure_ext)
            fpth = os.path.join(ws, "..", "figures", fname)
            fig.savefig(fpth)
Esempio n. 6
0
def plot_scenario_results(sims, idx):
    if config.plotModel:
        print("Plotting model results...")
        sim_mf6gwf, sim_mf6gwt, sim_mf2005, sim_mt3dms = sims
        fs = USGSFigure(figure_type="graph", verbose=False)

        sim_ws = sim_mf6gwt.simulation_data.mfpath.get_sim_path()
        fname = os.path.join(sim_ws, "trans.obs.csv")
        mf6gwt_ra = np.genfromtxt(fname,
                                  names=True,
                                  delimiter=",",
                                  deletechars="")
        fig, axs = plt.subplots(1,
                                1,
                                figsize=figure_size,
                                dpi=300,
                                tight_layout=True)
        axs.plot(
            mf6gwt_ra["time"],
            mf6gwt_ra["MYOBS"],
            markerfacecolor="None",
            markeredgecolor="b",
            marker="o",
            markersize="4",
            linestyle="None",
            label="MODFLOW 6 GWT",
        )
        sim_ws = sim_mt3dms.model_ws
        fname = os.path.join(sim_ws, "MT3D001.OBS")
        mt3dms_ra = sim_mt3dms.load_obs(fname)
        axs.plot(
            mt3dms_ra["time"],
            mt3dms_ra["(1, 1, 82)"],
            linestyle="-",
            color="k",
            label="MT3DMS",
        )
        axs.legend()
        title = "Case {} ".format(idx + 1)
        letter = chr(ord("@") + idx + 1)
        fs.heading(letter=letter, heading=title)

        # save figure
        if config.plotSave:
            sim_folder = os.path.split(sim_ws)[0]
            sim_folder = os.path.basename(sim_folder)
            fname = "{}{}".format(sim_folder, config.figure_ext)
            fpth = os.path.join(ws, "..", "figures", fname)
            fig.savefig(fpth)
def plot_results(sims):
    if config.plotModel:
        print("Plotting model results...")
        sim_mf6gwf, sim_mf6gwt = sims
        fs = USGSFigure(figure_type="map", verbose=False)

        conc = sim_mf6gwt.trans.output.concentration().get_data()

        fig, axs = plt.subplots(
            1, 1, figsize=figure_size, dpi=300, tight_layout=True
        )

        gwt = sim_mf6gwt.trans
        pmv = flopy.plot.PlotMapView(model=gwt, ax=axs)
        levels = [1, 3, 10, 30, 100, 300]
        cs1 = plot_analytical(axs, levels)
        cs2 = pmv.contour_array(
            conc, colors="blue", linestyles="--", levels=levels
        )
        axs.set_xlabel("x position (m)")
        axs.set_ylabel("y position (m)")
        axs.set_aspect(4.0)

        labels = ["Analytical", "MODFLOW 6"]
        lines = [cs1.collections[0], cs2.collections[0]]
        axs.legend(lines, labels, loc="upper left")

        # save figure
        if config.plotSave:
            sim_ws = sim_mf6gwt.simulation_data.mfpath.get_sim_path()
            sim_folder = os.path.split(sim_ws)[0]
            sim_folder = os.path.basename(sim_folder)
            fname = "{}-map{}".format(sim_folder, config.figure_ext)
            fpth = os.path.join(ws, "..", "figures", fname)
            fig.savefig(fpth)
def plot_grid(idx, sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_name = list(parameters.keys())[idx]
    gwf_outer = sim.get_model(gwfname_outer)
    gwf_inner = sim.get_model(gwfname_inner)

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf_outer, ax=ax, layer=0)
    pmv_inner = flopy.plot.PlotMapView(model=gwf_inner, ax=ax, layer=0)

    pmv.plot_grid()
    pmv_inner.plot_grid()

    pmv.plot_bc(name="CHD-LEFT", alpha=0.75)
    pmv.plot_bc(name="CHD-RIGHT", alpha=0.75)

    ax.plot([200, 500, 500, 200, 200], [200, 200, 500, 500, 200],
            "r--",
            linewidth=2.0)

    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-grid{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return
def plot_head(idx, sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_name = list(parameters.keys())[idx]
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    fname = os.path.join(sim_ws, "{}.hds".format(sim_name))
    hdobj = flopy.utils.HeadFile(fname)
    head = hdobj.get_data()

    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)
    cb = pmv.plot_array(0 - head, cmap="jet", alpha=0.25)
    cs = pmv.contour_array(0 - head, levels=np.arange(0.1, 1, 0.1))
    cbar = plt.colorbar(cb, shrink=0.25)
    cbar.ax.set_xlabel(r"Drawdown, ($m$)")
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-head{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return
def plot_grid(sims):
    if config.plotModel:
        print("Plotting model results...")
        sim_mf6gwf, sim_mf6gwt = sims
        fs = USGSFigure(figure_type="map", verbose=False)

        sim_ws = sim_mf6gwt.simulation_data.mfpath.get_sim_path()
        fig, axs = plt.subplots(1,
                                1,
                                figsize=figure_size,
                                dpi=300,
                                tight_layout=True)
        gwt = sim_mf6gwt.trans
        pmv = flopy.plot.PlotMapView(model=gwt, ax=axs)
        pmv.plot_grid()
        axs.set_xlabel("x position (m)")
        axs.set_ylabel("y position (m)")
        axs.set_aspect(4.0)

        # save figure
        if config.plotSave:
            sim_folder = os.path.split(sim_ws)[0]
            sim_folder = os.path.basename(sim_folder)
            fname = "{}-grid{}".format(sim_folder, config.figure_ext)
            fpth = os.path.join(ws, "..", "figures", fname)
            fig.savefig(fpth)
def make_animated_gif(sim, idx):
    from matplotlib.animation import FuncAnimation, PillowWriter

    fs = USGSFigure(figure_type="map", verbose=False)
    sim_name = example_name
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model("flow")
    gwt = sim.get_model("trans")

    cobj = gwt.output.concentration()
    times = cobj.get_times()
    times = np.array(times)
    conc = cobj.get_alldata()

    fig = plt.figure(figsize=(6, 4))
    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pxs = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={"row": 0})
    pc = pxs.plot_array(conc[0], cmap="jet", vmin=conc_inflow, vmax=conc_sat)

    def init():
        ax.set_xlim(0, 75.0)
        ax.set_ylim(0, 75.0)
        ax.set_title("Time = {} seconds".format(times[0]))

    def update(i):
        pc.set_array(conc[i].flatten())
        ax.set_title("Time = {} seconds".format(times[i]))

    ani = FuncAnimation(fig, update, range(1, times.shape[0]), init_func=init)
    writer = PillowWriter(fps=50)
    fpth = os.path.join("..", "figures", "{}{}".format(sim_name, ".gif"))
    ani.save(fpth, writer=writer)
    return
def plot_conc(sim, idx):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_name = list(parameters.keys())[idx]
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model("flow")
    gwt = sim.get_model("trans")

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    # create MODFLOW 6 head object
    fpth = os.path.join(sim_ws, "trans.ucn")
    cobj = flopy.utils.HeadFile(fpth, text="concentration")
    conc = cobj.get_data()

    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pxs = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={"row": 0})
    pxs.plot_array(conc, cmap="jet")
    levels = [35 * f for f in [0.01, 0.1, 0.5, 0.9, 0.99]]
    cs = pxs.contour_array(conc,
                           levels=levels,
                           colors="w",
                           linewidths=1.0,
                           linestyles="-")
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("z position (m)")
    plt.clabel(cs, fmt="%4.2f", fontsize=5)

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-conc{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return
Esempio n. 13
0
def plot_grid(sim):
    print("Plotting grid for {}...".format(sim.name))
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = sim.simulation_data.mfpath.get_sim_path()
    sim_name = sim.name
    gwf = sim.get_model("parent")
    gwfc = None
    if "child" in list(sim.model_names):
        gwfc = sim.get_model("child")

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)
    # pmv.plot_grid()
    idomain = gwf.dis.idomain.array
    tp = np.ma.masked_where(idomain[0] == 0, gwf.dis.top.array)
    vmin = tp.min()
    vmax = tp.max()
    if gwfc is not None:
        tpc = gwfc.dis.top.array
        vmin = min(vmin, tpc.min())
        vmax = max(vmax, tpc.max())

    cb = pmv.plot_array(tp, cmap="jet", alpha=0.25, vmin=vmin, vmax=vmax)
    pmv.plot_bc(name="RIV")
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")
    cbar = plt.colorbar(cb, shrink=0.5)
    cbar.ax.set_xlabel(r"Top, ($m$)")
    if gwfc is not None:
        pmv = flopy.plot.PlotMapView(model=gwfc, ax=ax, layer=0)
        _ = pmv.plot_array(
            tpc,
            cmap="jet",
            alpha=0.25,
            masked_values=[1e30],
            vmin=vmin,
            vmax=vmax,
        )
        pmv.plot_bc(name="RIV")
    if gwfc is not None:
        xmin, xmax, ymin, ymax = child_domain
        ax.plot(
            [xmin, xmax, xmax, xmin, xmin],
            [ymin, ymin, ymax, ymax, ymin],
            "k--",
        )
    xmin, xmax, ymin, ymax = model_domain
    ax.set_xlim(xmin, xmax)
    ax.set_ylim(ymin, ymax)

    # save figure
    if config.plotSave:
        fpth = os.path.join(
            "..", "figures", "{}-grid{}".format(sim_name, config.figure_ext)
        )
        fig.savefig(fpth)
    return
def plot_spdis(sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    # create MODFLOW 6 cell-by-cell budget object
    qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(
        gwf.output.budget().get_data(text="DATA-SPDIS", totim=1.0)[0],
        gwf,
    )

    ax = fig.add_subplot(1, 1, 1)
    pxs = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={"column": 0})
    pxs.plot_grid(linewidth=0.5)
    pxs.plot_vector(qx, qy, qz, normalize=True)
    ax.set_xlabel("y position (m)")
    ax.set_ylabel("z position (m)")

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-spdis{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return
Esempio n. 15
0
def plot_xsect(sim):
    print("Plotting cross section for {}...".format(sim.name))
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = sim.simulation_data.mfpath.get_sim_path()
    sim_name = sim.name
    gwf = sim.get_model("parent")

    fig = plt.figure(figsize=(5, 2.5))
    fig.tight_layout()

    ax = fig.add_subplot(1, 1, 1)
    irow, icol = gwf.modelgrid.intersect(3000.0, 3000.0)
    pmv = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={"column": icol})
    pmv.plot_grid(linewidth=0.5)
    hyc = np.log(gwf.npf.k.array)
    cb = pmv.plot_array(hyc, cmap="jet", alpha=0.25)
    ax.set_xlabel("y position (m)")
    ax.set_ylabel("z position (m)")
    cbar = plt.colorbar(cb, shrink=0.5)
    cbar.ax.set_xlabel(r"K, ($m/s$)")

    # save figure
    if config.plotSave:
        fpth = os.path.join(
            "..", "figures", "{}-xsect{}".format(sim_name, config.figure_ext)
        )
        fig.savefig(fpth)
    return
Esempio n. 16
0
def plot_head_results(sims, idx):
    print("Plotting head model results...")
    sim_mf6gwf, sim_mf6gwt, sim_mf2005, sim_mt3dms = sims
    gwf = sim_mf6gwf.flow
    botm = gwf.dis.botm.array
    # gwt = sim_mf6gwt.trans
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = sim_mf6gwf.simulation_data.mfpath.get_sim_path()
    head = gwf.output.head().get_data()
    head = np.where(head > botm, head, np.nan)
    fig, ax = plt.subplots(
        1, 1, figsize=figure_size, dpi=300, tight_layout=True
    )
    pxs = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={"row": 0})
    pa = pxs.plot_array(head, head=head, cmap="jet")
    pxs.plot_bc(ftype="RCH", color="red")
    pxs.plot_bc(ftype="CHD")
    plt.colorbar(pa, shrink=0.5)
    confining_rect = matplotlib.patches.Rectangle(
        (3000, 1000), 3000, 100, color="gray", alpha=0.5
    )
    ax.add_patch(confining_rect)
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("elevation (m)")
    ax.set_aspect(plotaspect)

    # save figure
    if config.plotSave:
        sim_folder = os.path.split(sim_ws)[0]
        sim_folder = os.path.basename(sim_folder)
        fname = "{}-head{}".format(sim_folder, config.figure_ext)
        fpth = os.path.join(ws, "..", "figures", fname)
        fig.savefig(fpth)
def plot_spdis(sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    # create MODFLOW 6 cell-by-cell budget object
    file_name = gwf.oc.budget_filerecord.get_data()[0][0]
    fpth = os.path.join(sim_ws, file_name)
    cobj = flopy.utils.CellBudgetFile(fpth, precision="double")
    spdis = cobj.get_data(text="DATA-SPDIS", totim=1.0)

    ax = fig.add_subplot(1, 1, 1)
    pxs = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={"column": 0})
    pxs.plot_grid(linewidth=0.5)
    pxs.plot_specific_discharge(spdis, normalize=True)
    ax.set_xlabel("y position (m)")
    ax.set_ylabel("z position (m)")

    # save figure
    if config.plotSave:
        fpth = os.path.join(
            "..", "figures", "{}-spdis{}".format(sim_name, config.figure_ext)
        )
        fig.savefig(fpth)
    return
def make_animated_gif(sims, idx):
    import matplotlib as mpl
    from matplotlib.animation import FuncAnimation, PillowWriter
    import copy

    print("Animating conc model results...")
    sim_name = example_name
    sim_mf6gwf, sim_mf6gwt, sim_mf2005, sim_mt3dms = sims
    gwf = sim_mf6gwf.flow
    gwt = sim_mf6gwt.trans
    botm = gwf.dis.botm.array

    # load head
    fs = USGSFigure(figure_type="map", verbose=False)
    head = gwf.output.head().get_data()
    head = np.where(head > botm, head, np.nan)

    # load concentration
    cobj = gwt.output.concentration()
    conc_times = cobj.get_times()
    conc_times = np.array(conc_times)
    conc = cobj.get_alldata()

    # set up the figure
    fig = plt.figure(figsize=(7.5, 3))
    ax = fig.add_subplot(1, 1, 1)
    pxs = flopy.plot.PlotCrossSection(
        model=gwf,
        ax=ax,
        line={"row": 0},
        extent=(0, 10000, 0, 2000),
    )

    cmap = copy.copy(mpl.cm.get_cmap("jet"))
    cmap.set_bad("white")
    nodata = -999.0
    a = np.where(head > botm, conc[0], nodata)
    a = np.ma.masked_where(a < 0, a)
    pc = pxs.plot_array(a, head=head, cmap=cmap, vmin=0, vmax=1)
    pxs.plot_bc(ftype="RCH", color="red")
    pxs.plot_bc(ftype="CHD")

    def init():
        ax.set_title("Time = {} days".format(conc_times[0]))

    def update(i):
        a = np.where(head > botm, conc[i], nodata)
        a = np.ma.masked_where(a < 0, a)
        a = a[~a.mask]
        pc.set_array(a.flatten())
        ax.set_title("Time = {} days".format(conc_times[i]))

    # Stop the animation at 18,000 days
    idx_end = (np.abs(conc_times - 18000.0)).argmin()
    ani = FuncAnimation(fig, update, range(1, idx_end), init_func=init)
    writer = PillowWriter(fps=25)
    fpth = os.path.join("..", "figures", "{}{}".format(sim_name, ".gif"))
    ani.save(fpth, writer=writer)
    return
def plot_heads(sim):
    print("Plotting results for {} ...".format(sim.name))
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = sim.simulation_data.mfpath.get_sim_path()
    sim_name = sim.name
    gwf = sim.get_model("parent")
    modelname = gwf.name
    gwfc = None
    if "child" in list(sim.model_names):
        gwfc = sim.get_model("child")

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    print("  Loading heads...")
    layer = 0
    head = gwf.output.head().get_data()
    head = np.ma.masked_where(head > 1e29, head)
    vmin = head[layer].min()
    vmax = head[layer].max()
    if gwfc is not None:
        headc = gwfc.output.head().get_data()
        vmin = min(vmin, headc.min())
        vmax = max(vmax, headc.max())

    print("  Making figure...")
    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)
    cb = pmv.plot_array(
        head, cmap="jet", masked_values=[1e30], vmin=vmin, vmax=vmax
    )
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")
    cbar = plt.colorbar(cb, shrink=0.5)
    cbar.ax.set_xlabel(r"Head, ($m$)")
    if gwfc is not None:
        pmv = flopy.plot.PlotMapView(model=gwfc, ax=ax, layer=0)
        cb = pmv.plot_array(
            headc, cmap="jet", masked_values=[1e30], vmin=vmin, vmax=vmax
        )
        xmin, xmax, ymin, ymax = child_domain
        ax.plot(
            [xmin, xmax, xmax, xmin, xmin],
            [ymin, ymin, ymax, ymax, ymin],
            "k--",
        )
    xmin, xmax, ymin, ymax = model_domain
    ax.set_xlim(xmin, xmax)
    ax.set_ylim(ymin, ymax)

    # save figure
    if config.plotSave:
        fpth = os.path.join(
            "..", "figures", "{}-head{}".format(sim_name, config.figure_ext)
        )
        fig.savefig(fpth)
    return
Esempio n. 20
0
def plot_grid(sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    # create MODFLOW 6 head object
    file_name = gwf.oc.head_filerecord.get_data()[0][0]
    fpth = os.path.join(sim_ws, file_name)
    hobj = flopy.utils.HeadFile(fpth)
    head = hobj.get_data()

    # create MODFLOW 6 cell-by-cell budget object
    file_name = gwf.oc.budget_filerecord.get_data()[0][0]
    fpth = os.path.join(sim_ws, file_name)
    cobj = flopy.utils.CellBudgetFile(fpth, precision="double")
    spdis = cobj.get_data(text="DATA-SPDIS", totim=1.0)

    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pxs = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={"row": 0})
    # pxs.plot_grid()
    pxs.plot_bc(name="CHD")
    pxs.plot_array(head, cmap="jet")
    levels = np.arange(-1, 1, 0.1)
    cs = pxs.contour_array(head,
                           levels=levels,
                           colors="k",
                           linewidths=1.0,
                           linestyles="-")
    pxs.plot_specific_discharge(spdis, normalize=False, kstep=5, hstep=5)
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("z position (m)")
    ax.set_ylim(-3, 0)
    fs.remove_edge_ticks(ax)
    plt.clabel(cs, fmt="%3.1f", fontsize=5)

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-grid{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return
def plot_results(sims, idx):
    if config.plotModel:
        print("Plotting model results...")
        sim_mf6gwf, sim_mf6gwt, sim_mf2005, sim_mt3dms = sims
        gwf = sim_mf6gwf.flow
        gwt = sim_mf6gwt.trans
        fs = USGSFigure(figure_type="map", verbose=False)

        sim_ws = sim_mf6gwt.simulation_data.mfpath.get_sim_path()
        fname = os.path.join(sim_ws, "trans.ucn")
        cobj = flopy.utils.HeadFile(fname, text="CONCENTRATION")
        conc = cobj.get_data()

        sim_ws = sim_mt3dms.model_ws
        fname = os.path.join(sim_ws, "MT3D001.UCN")
        cobjmt = flopy.utils.UcnFile(fname)
        concmt = cobjmt.get_data()

        fig, ax = plt.subplots(1,
                               1,
                               figsize=figure_size,
                               dpi=300,
                               tight_layout=True)
        pmv = flopy.plot.PlotMapView(model=gwf, ax=ax)
        pmv.plot_bc(ftype="MAW", color="red")
        pmv.plot_bc(ftype="CHD")
        pmv.plot_grid(linewidths=0.25)

        a = np.ma.masked_less(conc, 0.01)
        pa = pmv.plot_array(a, cmap="jet", alpha=0.25)
        plt.colorbar(pa, shrink=0.5)

        levels = [0.01, 0.1, 1, 10, 100]
        cs1 = pmv.contour_array(concmt, levels=levels, colors="r")

        cs2 = pmv.contour_array(conc,
                                levels=levels,
                                colors="b",
                                linestyles="--")
        ax.clabel(cs2, cs2.levels[::1], fmt="%3.2f", colors="b")

        labels = ["MT3DMS", "MODFLOW 6"]
        lines = [cs1.collections[0], cs2.collections[0]]
        ax.legend(lines, labels, loc="lower right")

        ax.set_xlabel("x position (m)")
        ax.set_ylabel("y position (m)")

        # save figure
        if config.plotSave:
            sim_folder = os.path.split(sim_ws)[0]
            sim_folder = os.path.basename(sim_folder)
            fname = "{}-map{}".format(sim_folder, config.figure_ext)
            fpth = os.path.join(ws, "..", "figures", fname)
            fig.savefig(fpth)
def plot_results():
    if config.plotModel:
        print("Plotting model results...")

        fs = USGSFigure(figure_type="graph", verbose=False)
        fig, axs = plt.subplots(1,
                                1,
                                figsize=figure_size,
                                dpi=300,
                                tight_layout=True)

        case_colors = ["blue", "green", "red", "yellow"]
        pkeys = list(parameters.keys())
        for icase, sim_name in enumerate(pkeys[2:]):

            sim_ws = os.path.join(ws, sim_name)
            beta = parameters[sim_name]["beta"]

            fname = os.path.join(sim_ws, "mf6gwt", "trans.obs.csv")
            mf6gwt_ra = np.genfromtxt(fname,
                                      names=True,
                                      delimiter=",",
                                      deletechars="")
            mf6conc = mf6gwt_ra["X008"] / source_concentration
            iskip = 20
            axs.plot(
                mf6gwt_ra["time"][::iskip],
                mf6conc[::iskip],
                markerfacecolor="None",
                markeredgecolor="k",
                marker="o",
                markersize="3",
                linestyle="None",
            )

            fname = os.path.join(sim_ws, "mt3d", "MT3D001.OBS")
            mt3dms_ra = flopy.mt3d.Mt3dms.load_obs(fname)
            axs.plot(
                mt3dms_ra["time"],
                mt3dms_ra["(1, 1, 51)"] / source_concentration,
                color=case_colors[icase],
                label="beta {}".format(beta),
            )

        axs.set_ylim(0, 1)
        axs.set_xlabel("Time (days)")
        axs.set_ylabel("Normalized Concentration (unitless)")
        axs.legend()

        # save figure
        if config.plotSave:
            fname = "{}{}".format(example_name, config.figure_ext)
            fpth = os.path.join("..", "figures", fname)
            fig.savefig(fpth)
    return
def plot_results_ct(sims, idx, **kwargs):
    if config.plotModel:
        print("Plotting C versus t model results...")
        sim_mf6gwf, sim_mf6gwt, sim_mf2005, sim_mt3dms = sims
        fs = USGSFigure(figure_type="graph", verbose=False)

        sim_ws = sim_mf6gwt.simulation_data.mfpath.get_sim_path()
        fname = os.path.join(sim_ws, "trans.obs.csv")
        mf6gwt_ra = np.genfromtxt(fname,
                                  names=True,
                                  delimiter=",",
                                  deletechars="")
        fig, axs = plt.subplots(1,
                                1,
                                figsize=figure_size,
                                dpi=300,
                                tight_layout=True)

        sim_ws = sim_mt3dms.model_ws
        fname = os.path.join(sim_ws, "MT3D001.OBS")
        mt_ra = sim_mt3dms.load_obs(fname)
        axs.plot(
            mt_ra["time"],
            mt_ra["(1, 1, 51)"] / source_concentration,
            color="k",
            label="MT3DMS",
        )

        axs.plot(
            mf6gwt_ra["time"],
            mf6gwt_ra["X008"] / source_concentration,
            ls="--",
            color="blue",
            # marker="o",
            # mec="blue",
            # mfc="none",
            # markersize="3",
            label="MODFLOW 6",
        )
        axs.set_ylim(0.0, 1.0)
        if idx == 0:
            axs.set_ylim(0, 0.5)
        if idx == 1:
            axs.set_xlim(0, 500)
        axs.set_xlabel("Time (seconds)")
        axs.set_ylabel("Normalized Concentration (unitless)")
        axs.legend()

        # save figure
        if config.plotSave:
            sim_folder = os.path.split(sim_ws)[0]
            sim_folder = os.path.basename(sim_folder)
            fname = "{}-ct{}".format(sim_folder, config.figure_ext)
            fpth = os.path.join(ws, "..", "figures", fname)
            fig.savefig(fpth)
Esempio n. 24
0
def plot_results():
    if config.plotModel:
        print("Plotting model results...")

        fs = USGSFigure(figure_type="graph", verbose=False)
        fig, axs = plt.subplots(1,
                                1,
                                figsize=figure_size,
                                dpi=300,
                                tight_layout=True)

        case_colors = ["blue", "green", "red"]
        for icase, sim_name in enumerate(parameters.keys()):

            sim_ws = os.path.join(ws, sim_name)

            fname = os.path.join(sim_ws, "mf6gwt", "trans.obs.csv")
            mf6gwt_ra = np.genfromtxt(fname,
                                      names=True,
                                      delimiter=",",
                                      deletechars="")
            axs.plot(
                mf6gwt_ra["time"],
                mf6gwt_ra["MYOBS"],
                markerfacecolor="None",
                markeredgecolor="k",
                marker="o",
                markersize="4",
                linestyle="None",
            )

            fname = os.path.join(sim_ws, "mt3d", "MT3D001.OBS")
            mt3dms_ra = flopy.mt3d.Mt3dms.load_obs(fname)
            axs.plot(
                mt3dms_ra["time"],
                mt3dms_ra["(1, 1, 82)"],
                color=case_colors[icase],
                label="Scenario {}".format(icase + 1),
            )

        axs.set_ylim(0, 16)
        axs.set_xlabel("Time (days)")
        axs.set_ylabel("Normalized Concentration (unitless)")
        axs.legend()

        # save figure
        if config.plotSave:
            fname = "{}{}".format("ex-gwt-mt3dsupp632", config.figure_ext)
            fpth = os.path.join("..", "figures", fname)
            fig.savefig(fpth)
    return
def plot_results(sims, idx):
    if config.plotModel:
        print("Plotting model results...")
        sim_mf6gwf, sim_mf6gwt, sim_mf2005, sim_mt3dms = sims
        fs = USGSFigure(figure_type="graph", verbose=False)

        sim_ws = sim_mf6gwt.simulation_data.mfpath.get_sim_path()
        fname = os.path.join(sim_ws, "trans.obs.csv")
        mf6gwt_ra = np.genfromtxt(fname,
                                  names=True,
                                  delimiter=",",
                                  deletechars="")
        fig, axs = plt.subplots(1,
                                1,
                                figsize=figure_size,
                                dpi=300,
                                tight_layout=True)
        axs.plot(
            mf6gwt_ra["time"],
            mf6gwt_ra["MYOBS"],
            marker="o",
            ls="none",
            mec="blue",
            mfc="none",
            markersize="4",
            label="MODFLOW 6 GWT",
        )

        sim_ws = sim_mt3dms.model_ws
        fname = os.path.join(sim_ws, "MT3D001.OBS")
        mt3dms_ra = sim_mt3dms.load_obs(fname)
        colname = mt3dms_ra.dtype.names[2]
        axs.plot(
            mt3dms_ra["time"],
            mt3dms_ra[colname],
            linestyle="-",
            color="k",
            label="MT3DMS",
        )
        axs.set_xlabel("Time (days)")
        axs.set_ylabel("Normalized Concentration (unitless)")
        axs.legend()

        # save figure
        if config.plotSave:
            sim_folder = os.path.split(sim_ws)[0]
            sim_folder = os.path.basename(sim_folder)
            fname = "{}{}".format(sim_folder, config.figure_ext)
            fpth = os.path.join(ws, "..", "figures", fname)
            fig.savefig(fpth)
Esempio n. 26
0
def plot_grid(idx, sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_name = list(parameters.keys())[idx]
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)
    pmv.plot_grid()
    pmv.plot_bc(name="CHD-LEFT", alpha=0.75)
    pmv.plot_bc(name="CHD-RIGHT", alpha=0.75)
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")
    for i, (x, y) in enumerate(
            zip(gwf.modelgrid.xcellcenters, gwf.modelgrid.ycellcenters)):
        ax.text(
            x,
            y,
            "{}".format(i + 1),
            fontsize=6,
            horizontalalignment="center",
            verticalalignment="center",
        )
    v = gwf.disv.vertices.array
    ax.plot(v["xv"], v["yv"], "yo")
    for i in range(v.shape[0]):
        x, y = v["xv"][i], v["yv"][i]
        ax.text(
            x,
            y,
            "{}".format(i + 1),
            fontsize=5,
            color="red",
            horizontalalignment="center",
            verticalalignment="center",
        )

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-grid{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return
Esempio n. 27
0
def plot_head(idx, sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_name = list(parameters.keys())[idx]
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)

    fig = plt.figure(figsize=(7.5, 5))
    fig.tight_layout()

    fname = os.path.join(sim_ws, "{}.hds".format(sim_name))
    hdobj = flopy.utils.HeadFile(fname)
    head = hdobj.get_data()[:, 0, :]

    # create MODFLOW 6 cell-by-cell budget object
    file_name = gwf.oc.budget_filerecord.get_data()[0][0]
    fpth = os.path.join(sim_ws, file_name)
    cobj = flopy.utils.CellBudgetFile(fpth, precision="double")
    spdis = cobj.get_data(text="DATA-SPDIS", totim=1.0)

    ax = fig.add_subplot(1, 2, 1, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)
    pmv.plot_grid()
    cb = pmv.plot_array(head, cmap="jet")
    pmv.plot_specific_discharge(
        spdis,
        normalize=False,
        color="0.75",
    )
    cbar = plt.colorbar(cb, shrink=0.25)
    cbar.ax.set_xlabel(r"Head, ($m$)")
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")
    fs.heading(ax, letter="A", heading="Simulated Head")

    ax = fig.add_subplot(1, 2, 2, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)
    pmv.plot_grid()
    x = np.array(gwf.modelgrid.xcellcenters) - 50.0
    slp = (1.0 - 0.0) / (50.0 - 650.0)
    heada = slp * x + 1.0
    cb = pmv.plot_array(head - heada, cmap="jet")
    cbar = plt.colorbar(cb, shrink=0.25)
    cbar.ax.set_xlabel(r"Error, ($m$)")
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")
    fs.heading(ax, letter="B", heading="Error")

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-head{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return
Esempio n. 28
0
def plot_boundary_heads(silent=True):
    verbose = not silent
    fs = USGSFigure(figure_type="graph", verbose=verbose)

    def process_dtw_obs(fpth):
        v = np.genfromtxt(fpth, names=True, delimiter=",")
        v["time"] /= 365.25
        v["time"] += 1908.353182752
        for key in v.dtype.names[1:]:
            v[key] *= -1.0
        return v

    name = list(parameters.keys())[0]
    pth = os.path.join(ws, name, "{}.gwf.obs.csv".format(name))
    hdata = process_dtw_obs(pth)

    pheads = ("HD01", "HD12", "HD14")
    hlabels = ("Upper aquifer", "Middle aquifer", "Lower aquifer")
    hcolors = ("green", "cyan", "blue")

    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(6.8, 6.8 / 3))

    ax.set_xlim(1907, 2007)
    ax.set_xticks(xticks)
    ax.set_ylim(50.0, -10.0)
    ax.set_yticks(sorted([50.0, 40.0, 30.0, 20.0, 10.0, 0.0, -10.0]))

    ax.plot([1907, 2007], [0, 0], lw=0.5, color="0.5")
    for idx, key in enumerate(pheads):
        ax.plot(
            hdata["time"],
            hdata[key],
            lw=0.75,
            color=hcolors[idx],
            label=hlabels[idx],
        )

    fs.graph_legend(ax=ax, frameon=False)
    ax.set_ylabel("Depth to water, in {}".format(length_units))
    ax.set_xlabel("Year")

    fs.remove_edge_ticks(ax=ax)

    fig.tight_layout()

    # save figure
    if config.plotSave:
        fpth = os.path.join(
            "..", "figures", "{}-01{}".format(sim_name, config.figure_ext)
        )
        if not silent:
            print("saving...'{}'".format(fpth))
        fig.savefig(fpth)
Esempio n. 29
0
def plot_head(idx, sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)

    fig = plt.figure(figsize=(7.5, 5))
    fig.tight_layout()

    head = gwf.output.head().get_data()[:, 0, :]

    # create MODFLOW 6 cell-by-cell budget object
    qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(
        gwf.output.budget().get_data(text="DATA-SPDIS", totim=1.0)[0],
        gwf,
    )

    ax = fig.add_subplot(1, 2, 1, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)
    cb = pmv.plot_array(head, cmap="jet", vmin=0.0, vmax=head.max())
    pmv.plot_vector(
        qx,
        qy,
        normalize=False,
        color="0.75",
    )
    cbar = plt.colorbar(cb, shrink=0.25)
    cbar.ax.set_xlabel(r"Head, ($m$)")
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")
    fs.heading(ax, letter="A", heading="Layer 1")

    ax = fig.add_subplot(1, 2, 2, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=1)
    cb = pmv.plot_array(head, cmap="jet", vmin=0.0, vmax=head.max())
    pmv.plot_vector(
        qx,
        qy,
        normalize=False,
        color="0.75",
    )
    cbar = plt.colorbar(cb, shrink=0.25)
    cbar.ax.set_xlabel(r"Head, ($m$)")
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")
    fs.heading(ax, letter="B", heading="Layer 2")

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-head{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return
Esempio n. 30
0
def plot_grid(idx, sim):
    fs = USGSFigure(figure_type="map", verbose=False)
    sim_ws = os.path.join(ws, sim_name)
    gwf = sim.get_model(sim_name)

    fig = plt.figure(figsize=figure_size)
    fig.tight_layout()

    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    pmv = flopy.plot.PlotMapView(model=gwf, ax=ax, layer=0)
    pmv.plot_grid(linewidth=1)
    pmv.plot_bc(name="GHB")
    ax.set_xlabel("x position (m)")
    ax.set_ylabel("y position (m)")

    # save figure
    if config.plotSave:
        fpth = os.path.join("..", "figures",
                            "{}-grid{}".format(sim_name, config.figure_ext))
        fig.savefig(fpth)
    return