From a74e62d2a869f9d046f19e7b076e4d9adbd332aa Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 23 Nov 2021 11:08:01 -0800 Subject: [PATCH 1/5] fix(plot_pathline): sort projected pathline points by travel time instead of cell order modflowpy#1302 --- flopy/plot/crosssection.py | 5 +++-- flopy/plot/plotutil.py | 8 +++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/flopy/plot/crosssection.py b/flopy/plot/crosssection.py index 8203d2474e..a1c8dcd00c 100644 --- a/flopy/plot/crosssection.py +++ b/flopy/plot/crosssection.py @@ -1069,8 +1069,9 @@ def plot_pathline( markers = [] for _, arr in plines.items(): arr = np.array(arr) - arr = arr[arr[:, 0].argsort()] - linecol.append(arr) + # sort by travel time + arr = arr[arr[:, -1].argsort()] + linecol.append(arr[:, :-1]) if marker is not None: for xy in arr[::markerevery]: markers.append(xy) diff --git a/flopy/plot/plotutil.py b/flopy/plot/plotutil.py index 8654e8d874..283ced0268 100644 --- a/flopy/plot/plotutil.py +++ b/flopy/plot/plotutil.py @@ -2681,9 +2681,7 @@ def intersect_modpath_with_crosssection( nppts = {} for cell, verts in projpts.items(): - tcell = cell - while tcell >= ncpl: - tcell -= ncpl + tcell = cell % ncpl zmin = np.min(np.array(verts)[:, 1]) zmax = np.max(np.array(verts)[:, 1]) nmin = np.min(v_norm[tcell]) @@ -2807,7 +2805,7 @@ def reproject_modpath_to_crosssection( rec[xp] = x rec[yp] = y pid = rec["particleid"][0] - pline = list(zip(rec[proj], rec[zp])) + pline = list(zip(rec[proj], rec[zp], rec['time'])) if pid not in ptdict: ptdict[pid] = pline else: @@ -2825,7 +2823,7 @@ def reproject_modpath_to_crosssection( rec[xp] = x rec[yp] = y pid = rec["particleid"][0] - pline = list(zip(rec[proj], rec[zp])) + pline = list(zip(rec[proj], rec[zp], rec['time'])) if pid not in ptdict: ptdict[pid] = pline else: From 7985d273c44ecb8d66b5ca3081a9e069f6af9627 Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 23 Nov 2021 11:13:17 -0800 Subject: [PATCH 2/5] Linting --- flopy/plot/plotutil.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flopy/plot/plotutil.py b/flopy/plot/plotutil.py index 283ced0268..478ee3ee82 100644 --- a/flopy/plot/plotutil.py +++ b/flopy/plot/plotutil.py @@ -2805,7 +2805,7 @@ def reproject_modpath_to_crosssection( rec[xp] = x rec[yp] = y pid = rec["particleid"][0] - pline = list(zip(rec[proj], rec[zp], rec['time'])) + pline = list(zip(rec[proj], rec[zp], rec["time"])) if pid not in ptdict: ptdict[pid] = pline else: @@ -2823,7 +2823,7 @@ def reproject_modpath_to_crosssection( rec[xp] = x rec[yp] = y pid = rec["particleid"][0] - pline = list(zip(rec[proj], rec[zp], rec['time'])) + pline = list(zip(rec[proj], rec[zp], rec["time"])) if pid not in ptdict: ptdict[pid] = pline else: From d5fbd12446f5bc7223626ddb157a36c6b9f4a46a Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 23 Nov 2021 15:20:09 -0800 Subject: [PATCH 3/5] fix(autotests): added pytest.ini to declare test naming convention * fixed t069_test_vtkexportmodel.py * updated voronoi tests in t075_test_ugrid.py * fixed ulstrd open/close read method for scale factors --- autotest/pytest.ini | 2 ++ autotest/t069_test_vtkexportmodel.py | 6 +++--- autotest/t075_test_ugrid.py | 24 ++++++++++++------------ flopy/utils/flopy_io.py | 1 + 4 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 autotest/pytest.ini diff --git a/autotest/pytest.ini b/autotest/pytest.ini new file mode 100644 index 0000000000..d783d708a4 --- /dev/null +++ b/autotest/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +python_files = *_test*.py \ No newline at end of file diff --git a/autotest/t069_test_vtkexportmodel.py b/autotest/t069_test_vtkexportmodel.py index 734ae38262..641b634dcd 100644 --- a/autotest/t069_test_vtkexportmodel.py +++ b/autotest/t069_test_vtkexportmodel.py @@ -14,10 +14,10 @@ def test_vtk_export_model_without_packages_names(): base_dir = base_test_dir(__file__, rel_path="temp", verbose=True) - test_setup = FlopyTestSetup(verbose=True, test_dirs=baseDir) + test_setup = FlopyTestSetup(verbose=True, test_dirs=base_dir) name = "mymodel" - sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=baseDir, exe_name="mf6") + sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=base_dir, exe_name="mf6") tdis = flopy.mf6.ModflowTdis(sim) ims = flopy.mf6.ModflowIms(sim) gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True) @@ -29,7 +29,7 @@ def test_vtk_export_model_without_packages_names(): ) # Export model without specifying packages_names parameter - vtk.export_model(sim.get_model(), baseDir) + vtk.export_model(sim.get_model(), base_dir) # If the function executes without error then test was successful assert True diff --git a/autotest/t075_test_ugrid.py b/autotest/t075_test_ugrid.py index 44010fc084..e3ccfd7386 100644 --- a/autotest/t075_test_ugrid.py +++ b/autotest/t075_test_ugrid.py @@ -279,7 +279,7 @@ def test_voronoi_grid0(plot=False): test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) name = "vor0" - answer_ncpl = 3804 + answer_ncpl = 3801 # 3804 domain = [ [1831.381546, 6335.543757], [4337.733475, 6851.136153], @@ -332,7 +332,7 @@ def test_voronoi_grid1(plot=False): test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) name = "vor1" - answer_ncpl = 1679 + answer_ncpl = 1662 # 1679 xmin = 0.0 xmax = 2.0 ymin = 0.0 @@ -368,7 +368,7 @@ def test_voronoi_grid2(plot=False): test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) name = "vor2" - answer_ncpl = 538 + answer_ncpl = 551 # 538 theta = np.arange(0.0, 2 * np.pi, 0.2) radius = 100.0 x = radius * np.cos(theta) @@ -486,7 +486,7 @@ def test_voronoi_grid5(plot=False): test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) name = "vor5" - answer_ncpl = 1067 + answer_ncpl = 1068 # 1067 active_domain = [(0, 0), (100, 0), (100, 100), (0, 100)] area1 = [(10, 10), (40, 10), (40, 40), (10, 40)] area2 = [(50, 50), (90, 50), (90, 90), (50, 90)] @@ -548,14 +548,14 @@ def test_voronoi_grid5(plot=False): if __name__ == "__main__": - # test_unstructured_grid_shell() - # test_unstructured_grid_dimensions() - # test_unstructured_minimal_grid() - # test_unstructured_complete_grid() - # test_loading_argus_meshes() - # test_create_unstructured_grid_from_verts() - # test_triangle_unstructured_grid() - # test_voronoi_vertex_grid() + #test_unstructured_grid_shell() + #test_unstructured_grid_dimensions() + #test_unstructured_minimal_grid() + #test_unstructured_complete_grid() + #test_loading_argus_meshes() + #test_create_unstructured_grid_from_verts() + #test_triangle_unstructured_grid() + test_voronoi_vertex_grid() test_voronoi_grid0(plot=True) test_voronoi_grid1(plot=True) test_voronoi_grid2(plot=True) diff --git a/flopy/utils/flopy_io.py b/flopy/utils/flopy_io.py index 27b0ab76c3..b7e2718704 100755 --- a/flopy/utils/flopy_io.py +++ b/flopy/utils/flopy_io.py @@ -462,6 +462,7 @@ def ulstrd(f, nlist, ra, model, sfac_columns, ext_unit_dict): # check for scaling factor if not binary: if line.strip().lower().startswith("sfac"): + line_list = line_parse(line) sfac = float(line_list[1]) line = file_handle.readline() From 12bacd47826ca5d1908193c9af1b19e3a623570c Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 23 Nov 2021 16:47:09 -0800 Subject: [PATCH 4/5] revert changes made to voronoi tests --- autotest/t075_test_ugrid.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autotest/t075_test_ugrid.py b/autotest/t075_test_ugrid.py index e3ccfd7386..9fb47e2184 100644 --- a/autotest/t075_test_ugrid.py +++ b/autotest/t075_test_ugrid.py @@ -332,7 +332,7 @@ def test_voronoi_grid1(plot=False): test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) name = "vor1" - answer_ncpl = 1662 # 1679 + answer_ncpl = 1679 xmin = 0.0 xmax = 2.0 ymin = 0.0 @@ -368,7 +368,7 @@ def test_voronoi_grid2(plot=False): test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) name = "vor2" - answer_ncpl = 551 # 538 + answer_ncpl = 538 theta = np.arange(0.0, 2 * np.pi, 0.2) radius = 100.0 x = radius * np.cos(theta) @@ -486,7 +486,7 @@ def test_voronoi_grid5(plot=False): test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) name = "vor5" - answer_ncpl = 1068 # 1067 + answer_ncpl = 1067 active_domain = [(0, 0), (100, 0), (100, 100), (0, 100)] area1 = [(10, 10), (40, 10), (40, 40), (10, 40)] area2 = [(50, 50), (90, 50), (90, 90), (50, 90)] From 26fdbfc2218795aaa9667a657ac1f799d738e4ea Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Tue, 23 Nov 2021 17:23:55 -0800 Subject: [PATCH 5/5] revert all changes to t075_test_ugrid.py --- autotest/t075_test_ugrid.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/autotest/t075_test_ugrid.py b/autotest/t075_test_ugrid.py index 9fb47e2184..44010fc084 100644 --- a/autotest/t075_test_ugrid.py +++ b/autotest/t075_test_ugrid.py @@ -279,7 +279,7 @@ def test_voronoi_grid0(plot=False): test_setup = FlopyTestSetup(verbose=True, test_dirs=model_ws) name = "vor0" - answer_ncpl = 3801 # 3804 + answer_ncpl = 3804 domain = [ [1831.381546, 6335.543757], [4337.733475, 6851.136153], @@ -548,14 +548,14 @@ def test_voronoi_grid5(plot=False): if __name__ == "__main__": - #test_unstructured_grid_shell() - #test_unstructured_grid_dimensions() - #test_unstructured_minimal_grid() - #test_unstructured_complete_grid() - #test_loading_argus_meshes() - #test_create_unstructured_grid_from_verts() - #test_triangle_unstructured_grid() - test_voronoi_vertex_grid() + # test_unstructured_grid_shell() + # test_unstructured_grid_dimensions() + # test_unstructured_minimal_grid() + # test_unstructured_complete_grid() + # test_loading_argus_meshes() + # test_create_unstructured_grid_from_verts() + # test_triangle_unstructured_grid() + # test_voronoi_vertex_grid() test_voronoi_grid0(plot=True) test_voronoi_grid1(plot=True) test_voronoi_grid2(plot=True)