Skip to content

Commit d2490a0

Browse files
mjrenomjreno
authored andcommitted
add plot to quickstart
1 parent e675046 commit d2490a0

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

docs/examples/image/quickstart.png

61.3 KB
Loading

docs/examples/qsplot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def _pcolormesh(grid, da, ax):
103103
ax.coastlines()
104104
ax.stock_img()
105105
ax.set_extent([-5, 15, -4, 14], crs=ccrs.PlateCarree())
106-
glines = ax.gridlines(draw_labels=True)
107-
glines.top_labels = False
108-
glines.right_labels = False
106+
gln = ax.gridlines(draw_labels=True)
107+
gln.top_labels = False
108+
gln.right_labels = False
109109
ax.set_title("Head")
110110
qsprj_pth = os.path.join(QS_ROOT, "image", "qsprj.png")
111111
fig.savefig(qsprj_pth)

docs/examples/quickstart.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
from pathlib import Path
2+
3+
import flopy
4+
import matplotlib.pyplot as plt
15
import numpy as np
6+
import xarray as xr
27

38
from flopy4.mf6.gwf import Chd, Dis, Gwf, Ic, Npf, Oc
49
from flopy4.mf6.ims import Ims
@@ -38,3 +43,51 @@
3843
# check OC
3944
assert oc.data["save_head"][0].item() == "all"
4045
assert oc.data["save_budget"][0].item() == "all"
46+
47+
# PLOT
48+
# create budget reader
49+
bpth = Path("./quickstart_data/mymodel.bud")
50+
bobj = flopy.utils.CellBudgetFile(bpth, precision="double")
51+
52+
# set specific discharge
53+
spdis = bobj.get_data(text="DATA-SPDIS")[0]
54+
55+
# create head reader
56+
hpth = Path("./quickstart_data/mymodel.hds")
57+
hobj = flopy.utils.HeadFile(hpth, precision="double")
58+
59+
# set heads
60+
heads = hobj.get_alldata()
61+
62+
# create grid
63+
grbpth = Path("./quickstart_data/mymodel.dis.grb")
64+
grid = flopy.discretization.StructuredGrid.from_binary_grid_file(grbpth)
65+
66+
# TODO: get_specific_discharge is dependent on flopy3 model
67+
# qx, qy, qz = flopy.utils.postprocessing.get_specific_discharge(spdis, gwf)
68+
69+
# set discharge component arrays
70+
u = []
71+
v = []
72+
for r in spdis:
73+
u.append(r[3])
74+
v.append(r[4])
75+
uflow = np.array(u).reshape(grid.nrow, grid.ncol)
76+
vflow = np.array(v).reshape(grid.nrow, grid.ncol)
77+
78+
# set data coordinate arrays
79+
xcrs = grid.xycenters[0]
80+
ycrs = grid.xycenters[1]
81+
82+
# create qx, qy dataarrys
83+
qx = xr.DataArray(uflow, dims=("y", "x"), coords={"x": xcrs, "y": ycrs})
84+
qy = xr.DataArray(vflow, dims=("y", "x"), coords={"x": xcrs, "y": ycrs})
85+
86+
fig, ax = plt.subplots()
87+
pmv = flopy.plot.PlotMapView(modelgrid=grid, ax=ax)
88+
pmv.plot_array(heads[0][0])
89+
pmv.plot_grid(colors="white")
90+
pmv.contour_array(heads[0][0], levels=[0.2, 0.4, 0.6, 0.8], linewidths=3.0)
91+
pmv.plot_vector(qx, qy, normalize=True, color="white")
92+
qs_pth = Path("./image/quickstart.png")
93+
fig.savefig(qs_pth)

0 commit comments

Comments
 (0)