From 548610c33e2ceca68cde77b4fa8fbbc1a88cfa42 Mon Sep 17 00:00:00 2001 From: Chris Nicol Date: Sun, 15 Aug 2021 11:52:55 +1000 Subject: [PATCH 1/2] 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. --- flopy/plot/map.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flopy/plot/map.py b/flopy/plot/map.py index 5b40708cf2..f822a6efae 100644 --- a/flopy/plot/map.py +++ b/flopy/plot/map.py @@ -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) From 991356d35709372081557c1a1c264f85ac8dcc4b Mon Sep 17 00:00:00 2001 From: Chris Nicol Date: Sun, 15 Aug 2021 14:00:14 +1000 Subject: [PATCH 2/2] add plot_bc tests to t506_test.py for unstructured mf6 and mfusg models --- autotest/t506_test.py | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/autotest/t506_test.py b/autotest/t506_test.py index b4d3716895..ea66d5af25 100644 --- a/autotest/t506_test.py +++ b/autotest/t506_test.py @@ -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 @@ -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 @@ -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)