From 85d4558cc28d75a87bd7892cd48a8d9c24ad578e Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Sat, 30 Apr 2022 11:53:55 -0700 Subject: [PATCH] fix(plot_pathline): split recarray into particle list when it contains multiple particle ids (#1400) * fix(plot_pathline): split recarray into particle list when it contains multiple particle ids * update MfListBudget docstrings * remove todo statements --- autotest/t057_test_mp7.py | 30 +++++++++++++++++++++++++++++- flopy/plot/map.py | 6 +++++- flopy/utils/mflistfile.py | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/autotest/t057_test_mp7.py b/autotest/t057_test_mp7.py index 4c5eee41a..e3991a86b 100644 --- a/autotest/t057_test_mp7.py +++ b/autotest/t057_test_mp7.py @@ -1,6 +1,7 @@ import os import numpy as np +import matplotlib.pyplot as plt from ci_framework import FlopyTestSetup, base_test_dir import flopy @@ -365,9 +366,36 @@ def build_mf6(model_ws): success, buff = mp.run_model() assert success, f"mp7 model ({mp.name}) did not run" - return + return gwf + + +def test_pathline_plotting(): + model_ws = f"{base_dir}_test_pathline_output" + test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) + + gwf = build_mf6(model_ws) + + modelgrid = gwf.modelgrid + nodes = list(range(modelgrid.nnodes)) + + if run: + fpth1 = os.path.join(model_ws, "mf6", "ex01_mf6_mp.mppth") + p = flopy.utils.PathlineFile(fpth1) + p1 = p.get_alldata() + pls = p.get_destination_data(nodes) + + pmv = flopy.plot.PlotMapView(modelgrid=modelgrid, layer=0) + pmv.plot_grid() + linecol = pmv.plot_pathline(pls, layer="all") + linecol2 = pmv.plot_pathline(p1, layer="all") + if not len(linecol._paths) == len(linecol2._paths): + raise AssertionError( + "plot_pathline not properly splitting particles from recarray" + ) + plt.close() if __name__ == "__main__": test_pathline_output() test_endpoint_output() + test_pathline_plotting() diff --git a/flopy/plot/map.py b/flopy/plot/map.py index 158b1f996..414df1804 100644 --- a/flopy/plot/map.py +++ b/flopy/plot/map.py @@ -735,7 +735,11 @@ def plot_pathline(self, pl, travel_time=None, **kwargs): # make sure pathlines is a list if not isinstance(pl, list): - pl = [pl] + pids = np.unique(pl["particleid"]) + if len(pids) > 1: + pl = [pl[pl["particleid"] == pid] for pid in pids] + else: + pl = [pl] if "layer" in kwargs: kon = kwargs.pop("layer") diff --git a/flopy/utils/mflistfile.py b/flopy/utils/mflistfile.py index 0de2ff55b..e3d7cd74b 100644 --- a/flopy/utils/mflistfile.py +++ b/flopy/utils/mflistfile.py @@ -39,7 +39,7 @@ class ListBudget: -------- >>> mf_list = MfListBudget("my_model.list") >>> incremental, cumulative = mf_list.get_budget() - >>> df_in, df_out = mf_list.get_dataframes(start_datetime="10-21-2015") + >>> df_inc, df_cumul = mf_list.get_dataframes(start_datetime="10-21-2015") """