From 61b66d936aef8d8c973780fa5c187349fbcb9d6e Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Mon, 20 Nov 2023 20:37:16 -0500 Subject: [PATCH] test roundtrip prt -> mp7 -> prt result conversion --- autotest/test_plotutil.py | 26 ++++++++++++++++++++++++-- flopy/plot/plotutil.py | 13 +++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/autotest/test_plotutil.py b/autotest/test_plotutil.py index 78b68cc710..0624abf926 100644 --- a/autotest/test_plotutil.py +++ b/autotest/test_plotutil.py @@ -2,12 +2,15 @@ import pandas as pd import pytest -from flopy.plot.plotutil import to_mp7_endpoints, to_mp7_pathlines +from flopy.plot.plotutil import ( + to_mp7_endpoints, + to_mp7_pathlines, + to_prt_pathlines, +) # test PRT-MP7 pathline conversion functions # todo: define fields in a single location and reference from here # todo: support optional grid parameter to conversion functions -# todo: test to_prt_pathlines() conversion and round-trip prt_pl_cols = [] @@ -289,3 +292,22 @@ def test_to_mp7_endpoints(dataframe): assert set( dict(mp7_eps.dtypes).keys() if dataframe else mp7_eps.dtype.names ) == set(mp7_ep_cols) + + +def test_to_prt_pathlines_roundtrip(): + inp_pls = pls + mp7_pls = to_mp7_pathlines(inp_pls) + prt_pls = to_prt_pathlines(mp7_pls) + inp_pls.drop( + ["imdl", "iprp", "name", "istatus", "ireason"], axis=1, inplace=True + ) + prt_pls.drop( + ["imdl", "iprp", "name", "istatus", "ireason"], axis=1, inplace=True + ) + inp_pls[inp_pls.select_dtypes(np.float64).columns] = inp_pls.select_dtypes( + np.float64 + ).astype(np.float32) + inp_pls[inp_pls.select_dtypes(np.int64).columns] = inp_pls.select_dtypes( + np.int64 + ).astype(np.int32) + assert np.array_equal(inp_pls, prt_pls) diff --git a/flopy/plot/plotutil.py b/flopy/plot/plotutil.py index 1776916779..4dcb013656 100644 --- a/flopy/plot/plotutil.py +++ b/flopy/plot/plotutil.py @@ -6,6 +6,7 @@ """ import os import warnings +from itertools import repeat from typing import Union import matplotlib.pyplot as plt @@ -2690,7 +2691,8 @@ def to_mp7_pathlines( # build mp7 format recarray ret = np.core.records.fromarrays( [ - data[seqn_key], + data["irpt"], + # data[seqn_key], data["iprp"], data[seqn_key], data["irpt"], @@ -2911,6 +2913,7 @@ def to_prt_pathlines( ("x", np.float32), ("y", np.float32), ("z", np.float32), + ("name", str), ] ) @@ -2920,17 +2923,19 @@ def to_prt_pathlines( data["stressperiod"], data["timestep"], np.zeros(data.shape[0]), - np.zeros(data.shape[0]), data["particlegroup"], data["particleid"], data["k"], data["node"], - np.zeros(data.shape[0]), # todo k + np.zeros(data.shape[0]), # todo izone? + np.zeros(data.shape[0]), # todo istatus? + np.zeros(data.shape[0]), # todo ireason? np.zeros(data.shape[0]), # todo trelease? - data["t"], + data["time"], data["x"], data["y"], data["z"], + np.zeros(data.shape[0]), ], dtype=prt_dtypes, )