Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plot/plot_bc) plot_bc fails with unstructured models #1185

Merged
merged 2 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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