From 6575fbbe5988ce88524a01eb06af15bc1013c5f2 Mon Sep 17 00:00:00 2001 From: Brioch Date: Fri, 2 May 2025 18:13:52 +1200 Subject: [PATCH] casting get_xy arg to tuple regardless -- think it is safe --- autotest/pst_from_tests.py | 36 ++++++++++++++++++++++++++++++++++-- pyemu/utils/pst_from.py | 3 +-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/autotest/pst_from_tests.py b/autotest/pst_from_tests.py index 5e73f0b1..282ce1f6 100644 --- a/autotest/pst_from_tests.py +++ b/autotest/pst_from_tests.py @@ -6191,6 +6191,38 @@ def arrayskip_test(tmp_path): pass +def test_sr_dict(tmp_path): + xs = np.arange(1000, 2000, 10) + ys = np.arange(2000, 3000, 10) + sr_dict = {(i, j): (x,y) for i, y in enumerate(ys) for j, x in enumerate(xs)} + gs = pyemu.geostats.GeoStruct(variograms=pyemu.geostats.ExpVario(contribution=1, a=250)) + + parfile = pd.DataFrame(sr_dict.keys(), columns=['i', 'j']) + parfile['q'] = range(len(parfile.index)) + + md = Path(tmp_path, 'eg') + md.mkdir(parents=True, exist_ok=True) + parfile.to_csv(Path(md, "parfile.csv"), index=False, header=False) + parfile.to_csv(Path(md, "obsfile.csv"), index=False, header=True) + pf = PstFrom(original_d=md, new_d=Path(tmp_path, 'template'), + remove_existing=True, + longnames=True, spatial_reference=sr_dict, + zero_based=True) + pf.add_parameters("parfile.csv", + par_type="grid", + index_cols=[0, 1], + use_cols=[2], + geostruct=gs) + pf.add_observations("obsfile.csv", + insfile="obsfile.csv.ins", + prefix="obs_file", + index_cols=['i','j'], + use_cols='q', + ofile_sep=',') + pass + + + if __name__ == "__main__": #add_py_function_test('.') @@ -6235,9 +6267,9 @@ def arrayskip_test(tmp_path): # # pstfrom_profile() # mf6_freyberg_arr_obs_and_headerless_test() #usg_freyberg_test(".") - #vertex_grid_test() + # vertex_grid_test('.') #direct_quickfull_test() - #list_float_int_index_test() + # list_float_int_index_test('.') #freyberg_test() diff --git a/pyemu/utils/pst_from.py b/pyemu/utils/pst_from.py index a00316a7..bd5833c3 100644 --- a/pyemu/utils/pst_from.py +++ b/pyemu/utils/pst_from.py @@ -371,8 +371,7 @@ def _generic_get_xy(self, args, **kwargs): return i, j def _dict_get_xy(self, arg, **kwargs): - if isinstance(arg, list): - arg = tuple(arg) + arg = tuple(arg) if len(arg) == 1: arg = arg[0] xy = self._spatial_reference.get(arg, None)