def plot_grid(sim, silent=True): verbose = not silent fs = USGSFigure(figure_type="map", verbose=verbose) name = sim.name gwf = sim.get_model(name) fig, ax = plt.subplots(figsize=(6.8, 2.0)) mc = flopy.plot.PlotCrossSection(model=gwf, line={"Row": 0}, ax=ax) ax.fill_between([0, 1], y1=0, y2=botm, color="cyan", alpha=0.5) fs.add_text( ax=ax, text="Constant head", x=0.5, y=-500.0, bold=False, italic=False, transform=False, va="center", ha="center", fontsize=9, ) ax.fill_between([2, 3], y1=0, y2=botm, color="cyan", alpha=0.5) fs.add_text( ax=ax, text="Constant head", x=2.5, y=-500.0, bold=False, italic=False, transform=False, va="center", ha="center", fontsize=9, ) ax.fill_between([1, 2], y1=-499.5, y2=-500.5, color="brown", alpha=0.5) fs.add_annotation( ax=ax, text="Delay interbed", xy=(1.5, -510.0), xytext=(1.6, -300), bold=False, italic=False, fontsize=9, ha="center", va="center", zorder=100, arrowprops=arrow_props, ) mc.plot_grid(color="0.5", lw=0.5, zorder=100) ax.set_xlim(0, 3) ax.set_ylabel("Elevation, in meters") ax.set_xlabel("x-coordinate, in meters") fs.remove_edge_ticks(ax) plt.tight_layout() # save figure if config.plotSave: fpth = os.path.join("..", "figures", "{}-grid{}".format(sim_name, config.figure_ext)) if not silent: print("saving...'{}'".format(fpth)) fig.savefig(fpth)
def plot_grid(sim, silent=True): verbose = not silent fs = USGSFigure(figure_type="map", verbose=verbose) name = sim.name gwf = sim.get_model(name) extents = gwf.modelgrid.extent # read simulated heads pth = os.path.join(ws, name, "{}.hds".format(name)) hobj = flopy.utils.HeadFile(pth) h0 = hobj.get_data(kstpkper=(0, 0)) h1 = hobj.get_data(kstpkper=(59, 1)) hsxs0 = h0[0, 8, :] hsxs1 = h1[0, 8, :] # get delr array dx = gwf.dis.delr.array # create x-axis for cross-section hxloc = np.arange(1000, 2000.0 * 15, 2000.0) # set cross-section location y = 2000.0 * 11.5 xsloc = [(extents[0], extents[1]), (y, y)] # well locations w1loc = (9.5 * 2000.0, 11.75 * 2000.0) w2loc = (6.5 * 2000.0, 8.5 * 2000.0) fig = plt.figure(figsize=(6.8, 5), constrained_layout=True) gs = mpl.gridspec.GridSpec(7, 10, figure=fig, wspace=5) plt.axis("off") ax = fig.add_subplot(gs[:, 0:6]) # ax.set_aspect('equal') mm = flopy.plot.PlotMapView(model=gwf, ax=ax, extent=extents) mm.plot_grid(lw=0.5, color="0.5") mm.plot_bc(ftype="WEL", kper=1, plotAll=True) mm.plot_bc(ftype="CHD", color="blue") mm.plot_bc(ftype="RCH", color="green") mm.plot_inactive(color_noflow="0.75") mm.ax.plot(xsloc[0], xsloc[1], color="orange", lw=1.5) # contour steady state heads cl = mm.contour_array( h0, masked_values=[1.0e30], levels=np.arange(115, 200, 5), colors="black", linestyles="dotted", linewidths=0.75, ) ax.clabel(cl, fmt="%3i", inline_spacing=0.1) # well text fs.add_annotation( ax=ax, text="Well 1, layer 2", bold=False, italic=False, xy=w1loc, xytext=(w1loc[0] - 3200, w1loc[1] + 1500), ha="right", va="center", zorder=100, arrowprops=arrow_props, ) fs.add_annotation( ax=ax, text="Well 2, layer 4", bold=False, italic=False, xy=w2loc, xytext=(w2loc[0] + 3000, w2loc[1]), ha="left", va="center", zorder=100, arrowprops=arrow_props, ) ax.set_ylabel("y-coordinate, in meters") ax.set_xlabel("x-coordinate, in meters") fs.heading(ax, letter="A", heading="Map view") fs.remove_edge_ticks(ax) ax = fig.add_subplot(gs[0:5, 6:]) mm = flopy.plot.PlotCrossSection(model=gwf, ax=ax, line={"row": 8}) mm.plot_grid(lw=0.5, color="0.5") # items for legend mm.ax.plot( -1000, -1000, "s", ms=5, color="green", mec="black", mew=0.5, label="Recharge", ) mm.ax.plot( -1000, -1000, "s", ms=5, color="red", mec="black", mew=0.5, label="Well", ) mm.ax.plot( -1000, -1000, "s", ms=5, color="blue", mec="black", mew=0.5, label="Constant head", ) mm.ax.plot( -1000, -1000, "s", ms=5, color="0.75", mec="black", mew=0.5, label="Inactive", ) mm.ax.plot( [-1000, -1001], [-1000, -1000], color="orange", lw=1.5, label="Cross-section line", ) # aquifer coloring ax.fill_between([0, dx.sum()], y1=150, y2=-100, color="cyan", alpha=0.5) ax.fill_between([0, dx.sum()], y1=-100, y2=-150, color="#D2B48C", alpha=0.5) ax.fill_between([0, dx.sum()], y1=-150, y2=-350, color="#00BFFF", alpha=0.5) # well coloring ax.fill_between([dx.cumsum()[8], dx.cumsum()[9]], y1=50, y2=-100, color="red", lw=0) # labels fs.add_text( ax=ax, transform=False, bold=False, italic=False, x=300, y=-97, text="Upper aquifer", va="bottom", ha="left", fontsize=9, ) fs.add_text( ax=ax, transform=False, bold=False, italic=False, x=300, y=-147, text="Confining unit", va="bottom", ha="left", fontsize=9, ) fs.add_text( ax=ax, transform=False, bold=False, italic=False, x=300, y=-347, text="Lower aquifer", va="bottom", ha="left", fontsize=9, ) fs.add_text( ax=ax, transform=False, bold=False, italic=False, x=29850, y=53, text="Layer 1", va="bottom", ha="right", fontsize=9, ) fs.add_text( ax=ax, transform=False, bold=False, italic=False, x=29850, y=-97, text="Layer 2", va="bottom", ha="right", fontsize=9, ) fs.add_text( ax=ax, transform=False, bold=False, italic=False, x=29850, y=-147, text="Layer 3", va="bottom", ha="right", fontsize=9, ) fs.add_text( ax=ax, transform=False, bold=False, italic=False, x=29850, y=-347, text="Layer 4", va="bottom", ha="right", fontsize=9, ) ax.plot( hxloc, hsxs0, lw=0.75, color="black", ls="dotted", label="Steady-state\nwater level", ) ax.plot( hxloc, hsxs1, lw=0.75, color="black", ls="dashed", label="Water-level at the end\nof stress-period 2", ) ax.set_ylabel("Elevation, in meters") ax.set_xlabel("x-coordinate along model row 9, in meters") fs.graph_legend( mm.ax, ncol=2, bbox_to_anchor=(0.5, -0.6), borderaxespad=0, frameon=False, loc="lower center", ) fs.heading(ax, letter="B", heading="Cross-section view") fs.remove_edge_ticks(ax) # save figure if config.plotSave: fpth = os.path.join("..", "figures", "{}-grid{}".format(sim_name, config.figure_ext)) if not silent: print("saving...'{}'".format(fpth)) fig.savefig(fpth)
def plot_calibration(silent=True): verbose = not silent fs = USGSFigure(figure_type="graph", verbose=verbose) name = list(parameters.keys())[1] pth = os.path.join(ws, name, "{}.csub.obs.csv".format(name)) df_sim = get_sim_dataframe(pth) df_sim.rename({"TOTAL": "simulated"}, inplace=True, axis=1) pth = os.path.join("..", "data", sim_name, "boundary_heads.csv") df_obs_heads, col_list = process_sim_csv(pth) ccolors = ( "black", "tan", "cyan", "brown", "blue", "violet", ) xf0 = datetime.datetime(1907, 1, 1, 0, 0, 0) xf1 = datetime.datetime(2007, 1, 1, 0, 0, 0) xf0s = datetime.datetime(1990, 1, 1, 0, 0, 0) xf1s = datetime.datetime(2007, 1, 1, 0, 0, 0) xc0 = datetime.datetime(1992, 10, 1, 0, 0, 0) xc1 = datetime.datetime(2006, 9, 4, 0, 0, 0) dx = xc1 - xc0 xca = xc0 + dx / 2 # get observation data df = get_obs_dataframe(file_name="008N010W01Q005S_obs.csv") ix0 = df.index.get_loc("2006-09-04 00:00:00") offset = df_sim["simulated"].values[-1] - df.observed.values[ix0] df.observed += offset # -- subplot a ----------------------------------------------------------- # build box for subplot B o = datetime.timedelta(31) ix = (xf0s, xf0s, xf1s - o, xf1s - o, xf0s) iy = (1.15, 1.45, 1.45, 1.15, 1.15) # -- subplot a ----------------------------------------------------------- # -- subplot c ----------------------------------------------------------- # get observations df_pc = get_obs_dataframe() # get index for start of calibration period for subplot c ix0 = df_sim.index.get_loc("1992-10-01 12:00:00") # get initial simulated compaction cstart = df_sim.simulated[ix0] # cut off initial portion of simulated compaction df_sim_pc = df_sim[ix0:].copy() # reset initial compaction to 0. df_sim_pc.simulated -= cstart # reset simulated so maximum compaction is the same offset = df_pc.observed.values.max() - df_sim_pc.simulated.values[-1] df_sim.simulated += offset # interpolate subsidence observations to the simulation index for subplot c df_iobs_pc = dataframe_interp(df_pc, df_sim_pc.index) # truncate head to start of observations head_pc = dataframe_interp(df_obs_heads, df_sim_pc.index) # calculate geostatic stress gs = sgm * (0.0 - head_pc.CHD_L01.values) + sgs * ( head_pc.CHD_L01.values - botm[-1] ) # calculate hydrostatic stress for subplot c u = head_pc.CHD_L13.values - botm[-1] # calculate effective stress es_obs = gs - u # set up indices for date text for plot c locs = ["{:04d}-10-01 12:00:00".format(yr) for yr in range(1992, 2006)] locs += ["{:04d}-04-01 12:00:00".format(yr) for yr in range(1993, 2007)] locs += ["2006-09-04 12:00:00"] ixs = [head_pc.index.get_loc(loc) for loc in locs] # -- subplot c ----------------------------------------------------------- ctext = "Calibration period\n{} to {}".format( xc0.strftime("%B %d, %Y"), xc1.strftime("%B %d, %Y") ) fig, axes = plt.subplots(nrows=3, ncols=1, figsize=(6.8, 6.8)) # -- plot a -------------------------------------------------------------- ax = axes.flat[0] ax.set_xlim(xf0, xf1) ax.plot([xf0, xf1], [0, 0], lw=0.5, color="0.5") ax.plot( [ xf0, ], [ -10, ], marker=".", ms=1, lw=0, color="red", label="Holly site (8N/10W-1Q)", ) for idx, key in enumerate(pcomp): if key == "TOTAL": key = "simulated" color = ccolors[idx] label = clabels[idx] ax.plot( df_sim.index.values, df_sim[key].values, color=color, label=label, lw=0.75, ) ax.plot(ix, iy, lw=1.0, color="red", zorder=200) fs.add_text(ax=ax, text="B", x=xf0s, y=1.14, transform=False) ax.set_ylim(1.5, -0.1) ax.xaxis.set_ticks(df_xticks) ax.xaxis.set_major_formatter(mpl.dates.DateFormatter("%m/%d/%Y")) ax.set_ylabel("Compaction, in {}".format(length_units)) ax.set_xlabel("Year") fs.graph_legend(ax=ax, frameon=False) fs.heading(ax, letter="A") fs.remove_edge_ticks(ax=ax) # -- plot b -------------------------------------------------------------- ax = axes.flat[1] ax.set_xlim(xf0s, xf1s) ax.set_ylim(1.45, 1.15) ax.plot( df.index.values, df["observed"].values, marker=".", ms=1, lw=0, color="red", ) ax.plot( df_sim.index.values, df_sim["simulated"].values, color="black", label=label, lw=0.75, ) # plot lines for calibration ax.plot([xc0, xc0], [1.45, 1.15], color="black", lw=0.5, ls=":") ax.plot([xc1, xc1], [1.45, 1.15], color="black", lw=0.5, ls=":") fs.add_annotation( ax=ax, text=ctext, italic=False, bold=False, xy=(xc0 - o, 1.2), xytext=(xca, 1.2), ha="center", va="center", arrowprops=dict(arrowstyle="-|>", fc="black", lw=0.5), color="none", bbox=dict(boxstyle="square,pad=-0.07", fc="none", ec="none"), ) fs.add_annotation( ax=ax, text=ctext, italic=False, bold=False, xy=(xc1 + o, 1.2), xytext=(xca, 1.2), ha="center", va="center", arrowprops=dict(arrowstyle="-|>", fc="black", lw=0.5), bbox=dict(boxstyle="square,pad=-0.07", fc="none", ec="none"), ) ax.yaxis.set_ticks(np.linspace(1.15, 1.45, 7)) ax.xaxis.set_ticks(df_xticks1) ax.xaxis.set_major_locator(mpl.dates.YearLocator()) ax.xaxis.set_minor_locator(mpl.dates.YearLocator(month=6, day=15)) ax.xaxis.set_major_formatter(mpl.ticker.NullFormatter()) ax.xaxis.set_minor_formatter(mpl.dates.DateFormatter("%Y")) ax.tick_params(axis="x", which="minor", length=0) ax.set_ylabel("Compaction, in {}".format(length_units)) ax.set_xlabel("Year") fs.heading(ax, letter="B") fs.remove_edge_ticks(ax=ax) # -- plot c -------------------------------------------------------------- ax = axes.flat[2] ax.set_xlim(-0.01, 0.2) ax.set_ylim(368, 376) ax.plot( df_iobs_pc.observed.values, es_obs, marker=".", ms=1, color="red", lw=0, label="Holly site (8N/10W-1Q)", ) ax.plot( df_sim_pc.simulated.values, df_sim_pc.ES14.values, color="black", lw=0.75, label="Simulated", ) for idx, ixc in enumerate(ixs): text = "{}".format(df_iobs_pc.index[ixc].strftime("%m/%d/%Y")) if df_iobs_pc.index[ixc].month == 4: dxc = -0.001 dyc = -1 elif df_iobs_pc.index[ixc].month == 9: dxc = 0.002 dyc = 0.75 else: dxc = 0.001 dyc = 1 xc = df_iobs_pc.observed[ixc] yc = es_obs[ixc] fs.add_annotation( ax=ax, text=text, italic=False, bold=False, xy=(xc, yc), xytext=(xc + dxc, yc + dyc), ha="center", va="center", fontsize=7, arrowprops=dict(arrowstyle="-", color="red", fc="red", lw=0.5), bbox=dict(boxstyle="square,pad=-0.15", fc="none", ec="none"), ) xtext = "Total compaction since {}, in {}".format( df_sim_pc.index[0].strftime("%B %d, %Y"), length_units ) ytext = ( "Effective stress at the bottom of\nthe lower aquifer, in " + "{} of water".format(length_units) ) ax.set_xlabel(xtext) ax.set_ylabel(ytext) fs.heading(ax, letter="C") fs.remove_edge_ticks(ax=ax) fs.remove_edge_ticks(ax) # finalize figure fig.tight_layout(pad=0.01) # save figure if config.plotSave: fpth = os.path.join( "..", "figures", "{}-03{}".format(sim_name, config.figure_ext) ) if not silent: print("saving...'{}'".format(fpth)) fig.savefig(fpth)
def plot_local_grid(silent=True): if silent: verbosity = 0 else: verbosity = 1 name = list(parameters.keys())[1] sim_ws = os.path.join(ws, name) sim = flopy.mf6.MFSimulation.load( sim_name=sim_name, sim_ws=sim_ws, verbosity_level=verbosity ) gwf = sim.get_model(sim_name) i, j = maw_loc dx, dy = delr[j], delc[i] px = ( 50.0 - 0.5 * dx, 50.0 + 0.5 * dx, ) py = ( 0.0 + dy, 0.0 + dy, ) # get regional heads for constant head boundaries h = gwf.output.head().get_data() fs = USGSFigure(figure_type="map", verbose=False) fig = plt.figure( figsize=(6.3, 4.1), tight_layout=True, ) plt.axis("off") nrows, ncols = 10, 1 axes = [fig.add_subplot(nrows, ncols, (1, 8))] for idx, ax in enumerate(axes): ax.set_xlim(extents[:2]) ax.set_ylim(extents[2:]) ax.set_aspect("equal") # legend axis axes.append(fig.add_subplot(nrows, ncols, (8, 10))) # set limits for legend area ax = axes[-1] ax.set_xlim(0, 1) ax.set_ylim(0, 1) # get rid of ticks and spines for legend area ax.axis("off") ax.set_xticks([]) ax.set_yticks([]) ax.spines["top"].set_color("none") ax.spines["bottom"].set_color("none") ax.spines["left"].set_color("none") ax.spines["right"].set_color("none") ax.patch.set_alpha(0.0) ax = axes[0] mm = flopy.plot.PlotMapView(gwf, ax=ax, extent=extents, layer=0) mm.plot_bc("CHD", color="cyan", plotAll=True) mm.plot_grid(lw=0.25, color="0.5") cv = mm.contour_array( h, levels=np.arange(4.0, 5.0, 0.005), linewidths=0.5, linestyles="-", colors="black", masked_values=masked_values, ) plt.clabel(cv, fmt="%1.3f") ax.fill_between( px, py, y2=0, ec="none", fc="red", lw=0, zorder=200, step="post" ) fs.add_annotation( ax, text="Well location", xy=(50.0, 0.0), xytext=(55, 5), bold=False, italic=False, ha="left", fontsize=7, arrowprops=arrow_props, ) fs.remove_edge_ticks(ax) ax.set_xticks([0, 25, 50, 75, 100]) ax.set_xlabel("x-coordinate, in feet") ax.set_yticks([0, 25, 50]) ax.set_ylabel("y-coordinate, in feet") # legend ax = axes[-1] ax.plot( -10000, -10000, lw=0, marker="s", ms=10, mfc="cyan", mec="0.5", markeredgewidth=0.25, label="Constant head", ) ax.plot( -10000, -10000, lw=0, marker="s", ms=10, mfc="red", mec="0.5", markeredgewidth=0.25, label="Multi-aquifer well", ) ax.plot( -10000, -10000, lw=0.5, color="black", label="Water-table contour, $ft$", ) fs.graph_legend(ax, loc="lower center", ncol=3) # save figure if config.plotSave: fpth = os.path.join( "..", "figures", "{}-local-grid{}".format(sim_name, config.figure_ext), ) fig.savefig(fpth)