diff --git a/autotest/pst_from_tests.py b/autotest/pst_from_tests.py index 7d60e608..6529937d 100644 --- a/autotest/pst_from_tests.py +++ b/autotest/pst_from_tests.py @@ -4603,13 +4603,16 @@ def test_vertex_grid(tmp_path): df_pp = pf.add_parameters(f, zone_array=ib[layer], par_type="pilotpoints", - use_pp_zones=True, + #use_pp_zones=True, geostruct=grid_gs, par_name_base=f.split('.')[1].replace("_","")+"pp", pargp=f.split('.')[1].replace("_","")+"pp", lower_bound=0.2,upper_bound=5.0, ult_ubound=100, ult_lbound=0.01, - pp_space=500) # ` + pp_options={"prep_hyperpars":False, + "pp_space":500, + "try_use_ppu":False, + "pp_zones":True}) # ` tag = "sfr_packagedata" files = [f for f in os.listdir(template_ws) if tag in f.lower() and f.endswith(".txt")] @@ -4681,9 +4684,14 @@ def test_vertex_grid(tmp_path): k = int(f.split('_layer')[-1].split('.')[0]) - 1 a = np.loadtxt(os.path.join(template_ws, f)) a_org = np.loadtxt(os.path.join(template_ws,'org', f)) + assert a.shape == a_org.shape, (a.shape, a_org.shape) + assert np.isclose(a, a_org).all(), a-a_org # weak check - for zone in npfpar.loc[npfpar.pname.str.contains(f'layer{k+1}')].zone.unique(): - assert np.isclose(abs((a/a_org)[ib[k]==int(zone)]-int(zone)).max(), 0) + zones = npfpar.loc[npfpar.pname.str.contains(f'layer{k+1}')].zone.unique() + # check all of zones are in ib[k] + assert set(zones).issubset(set(np.unique(ib[k]))), f"not all zones in ib for {f}" + for zone in zones: + assert np.isclose(abs((a/a_org)[ib[k]==int(zone)]-1).max(), 0), f"{f} zone {zone} failed check" return def test_defaults(tmp_path): diff --git a/pyemu/utils/pp_utils.py b/pyemu/utils/pp_utils.py index eaefc9bb..e9593e62 100644 --- a/pyemu/utils/pp_utils.py +++ b/pyemu/utils/pp_utils.py @@ -783,6 +783,10 @@ def prep_pp_hyperpars(file_tag,pp_filename,pp_info,out_filename,grid_dict, aniso_filename = file_tag + ".aniso.dat" zone_filename = file_tag + ".zone.dat" + if len(arr_shape) == 1 and type(arr_shape) is tuple: + arr_shape = (1,arr_shape[0]) + + nodes = list(grid_dict.keys()) nodes.sort() with open(os.path.join(ws,gridinfo_filename), 'w') as f: @@ -798,7 +802,7 @@ def prep_pp_hyperpars(file_tag,pp_filename,pp_info,out_filename,grid_dict, np.savetxt(os.path.join(ws,aniso_filename), aniso, fmt="%20.8E") if zone_array is None: - zone_array = np.ones(shape,dtype=int) + zone_array = np.ones(arr_shape,dtype=int) np.savetxt(os.path.join(ws,zone_filename),zone_array,fmt="%5d") diff --git a/pyemu/utils/pst_from.py b/pyemu/utils/pst_from.py index 5a921489..ed07b512 100644 --- a/pyemu/utils/pst_from.py +++ b/pyemu/utils/pst_from.py @@ -2118,8 +2118,21 @@ def add_parameters( and zone_array is not None and len(zone_array.shape) == 1 ) + checker2 = ( + self._spatial_reference is not None + and not isinstance(self._spatial_reference, dict) + and self._spatial_reference.grid_type == 'vertex' + and zone_array is not None + and len(zone_array.shape) == 2 + and zone_array.shape[0] == 1 + and zone_array.shape[1] > 1 + ) if checker: zone_array = np.reshape(zone_array, (zone_array.shape[0], 1)) + # when accesing ib for a 1layer model, the returned array has shape (1,ncpl) + if checker2: + zone_array = np.reshape(zone_array, (zone_array.shape[1], 1)) + # Get useful variables from arguments passed # if index_cols passed as a dictionary that maps i,j information @@ -2452,7 +2465,7 @@ def add_parameters( orgdata = ar.shape for i, chk in checkref.items(): assert orgdata[i] == chk[1], ( - f"Spatial reference {chk[0]} not equal to original data {chk[0]} for\n" + f"Spatial reference {chk[1]} not equal to original data {orgdata[i]} for\n" + os.path.join( *os.path.split(self.original_file_d)[1:], mod_file )