Skip to content

Commit

Permalink
fix(plot/plot_bc) plot_bc fails with unstructured models (#1185)
Browse files Browse the repository at this point in the history
* fix(plot/plot_bc) plot_bc fails with unstructured models

In plot/map.py, with unstructred models, numpy throws "too many indices for array" error
when indexing plotarray with a tuple of boundary condition node numbers.

* Revert plotarray BC indices to stress_period_data list[kper]["node"] as-is for
unstructured models.

* add plot_bc tests to t506_test.py for unstructured mf6 and mfusg models
  • Loading branch information
cnicol-gwlogic authored Aug 16, 2021
1 parent 5974d80 commit e523256
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
61 changes: 61 additions & 0 deletions autotest/t506_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
try:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.collections import QuadMesh, PathCollection, LineCollection
except:
print("Matplotlib not installed, tests cannot be run.")
matplotlib = None
Expand Down Expand Up @@ -304,6 +305,36 @@ def test_mf6disu():
plt.savefig(fname)
plt.close("all")

# check plot_bc works for unstructured mf6 grids
# (for each layer, and then for all layers in one plot)
plot_ranges = [range(gwf.modelgrid.nlay), range(1)]
plot_alls = [False, True]
for plot_range, plot_all in zip(plot_ranges, plot_alls):
f_bc = plt.figure(figsize=(10, 10))
for ilay in plot_range:
ax = plt.subplot(1, plot_range[-1] + 1, ilay + 1)
pmv = flopy.plot.PlotMapView(gwf, layer=ilay, ax=ax)
ax.set_aspect("equal")

pmv.plot_bc(
"CHD", plotAll=plot_all, edgecolor="None", zorder=2
)
pmv.plot_grid(
colors="k", linewidth=0.3, alpha=0.1, zorder=1
)

if len(ax.collections) == 0:
raise AssertionError(
"Boundary condition was not drawn"
)

for col in ax.collections:
if not isinstance(
col, (QuadMesh, PathCollection, LineCollection)
):
raise AssertionError("Unexpected collection type")
plt.close()

return


Expand Down Expand Up @@ -399,6 +430,36 @@ def test_mfusg():
plt.savefig(fname)
plt.close("all")

# check plot_bc works for unstructured mfusg grids
# (for each layer, and then for all layers in one plot)
plot_ranges = [range(disu.nlay), range(1)]
plot_alls = [False, True]
for plot_range, plot_all in zip(plot_ranges, plot_alls):
f_bc = plt.figure(figsize=(10, 10))
for ilay in plot_range:
ax = plt.subplot(1, plot_range[-1] + 1, ilay + 1)
pmv = flopy.plot.PlotMapView(m, layer=ilay, ax=ax)
ax.set_aspect("equal")

pmv.plot_bc(
"CHD", plotAll=plot_all, edgecolor="None", zorder=2
)
pmv.plot_grid(
colors="k", linewidth=0.3, alpha=0.1, zorder=1
)

if len(ax.collections) == 0:
raise AssertionError(
"Boundary condition was not drawn"
)

for col in ax.collections:
if not isinstance(
col, (QuadMesh, PathCollection, LineCollection)
):
raise AssertionError("Unexpected collection type")
plt.close()

# re-run with an LPF keyword specified. This would have thrown an error
# before the addition of ikcflag to mflpf.py (flopy 3.3.3 and earlier).
lpf = flopy.modflow.ModflowLpf(m, novfc=True, nocvcorrection=True)
Expand Down
4 changes: 3 additions & 1 deletion flopy/plot/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,10 @@ def plot_bc(
pa[tuple(idx[1:])] = 1
for k in range(nlay):
plotarray[k] = pa.copy()
else:
elif len(self.mg.shape) > 1:
plotarray[tuple(idx)] = 1
else:
plotarray[idx] = 1

# mask the plot array
plotarray = np.ma.masked_equal(plotarray, 0)
Expand Down

0 comments on commit e523256

Please sign in to comment.