Skip to content

Commit 9d4be90

Browse files
committed
forgot also needed to make changes in method
1 parent 58eca97 commit 9d4be90

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

autotest/utils_tests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,7 @@ def hfb_zn_mult_test():
15181518
for i in range(m.nrow)[21:]:
15191519
hfb_data.append([0, i, jcol1, i, jcol2, 0.003])
15201520
flopy.modflow.ModflowHfb(m, 0, 0, len(hfb_data), hfb_data=hfb_data)
1521+
orig_len = len(m.hfb6.hfb_data)
15211522
m.change_model_ws("temp")
15221523
m.write_input()
15231524
m.exe_name = "mfnwt"
@@ -1528,19 +1529,20 @@ def hfb_zn_mult_test():
15281529

15291530
orig_vals, tpl_file = pyemu.gw_utils.write_hfb_zone_multipliers_template(m)
15301531
assert os.path.exists(tpl_file)
1531-
hfb_pars = pd.read_csv(os.path.join('temp', 'hfb6_pars.csv'))
1532+
hfb_pars = pd.read_csv(os.path.join(m.model_ws, 'hfb6_pars.csv'))
15321533
hfb_tpl_contents = open(tpl_file, 'r').readlines()
15331534
mult_str = ''.join(hfb_tpl_contents[1:]).replace(
15341535
'~ hbz_0000 ~', '0.1').replace(
15351536
'~ hbz_0001 ~', '1.0').replace(
15361537
'~ hbz_0002 ~', '10.0')
15371538
with open(hfb_pars.mlt_file.values[0], 'w') as mfp:
15381539
mfp.write(mult_str)
1539-
pyemu.helpers.apply_hfb_pars(os.path.join('temp', 'hfb6_pars.csv'))
1540+
pyemu.helpers.apply_hfb_pars(os.path.join(m.model_ws, 'hfb6_pars.csv'))
15401541
with open(hfb_pars.mlt_file.values[0], 'r') as mfp:
15411542
for i, line in enumerate(mfp):
15421543
pass
1543-
assert i-1 == m.hfb6.hfb_data.shape[0]
1544+
mhfb = flopy.modflow.ModflowHfb.load(hfb_pars.model_file.values[0], m)
1545+
assert i-1 == orig_len == len(mhfb.hfb_data)
15441546

15451547

15461548
def read_runstor_test():

pyemu/utils/gw_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ def write_hfb_zone_multipliers_template(m):
23622362
header = hfb_file_contents[:skiprows]
23632363

23642364
# read in the data
2365-
names = ['lay', 'irow1','icol1','irow2','icol2', 'hydchr']
2365+
names = ['lay', 'irow1', 'icol1', 'irow2', 'icol2', 'hydchr']
23662366
hfb_in = pd.read_csv(hfb_file, skiprows=skiprows,
23672367
delim_whitespace=True, names=names).dropna()
23682368
for cn in names[:-1]:
@@ -2386,7 +2386,7 @@ def write_hfb_zone_multipliers_template(m):
23862386
ofp.write('ptf ~\n')
23872387
[ofp.write('{0}\n'.format(line.strip())) for line in header]
23882388
ofp.flush()
2389-
hfb_in[['lay', 'irow1','icol1','irow2','icol2', 'tpl']].to_csv(
2389+
hfb_in[['lay', 'irow1', 'icol1', 'irow2', 'icol2', 'tpl']].to_csv(
23902390
ofp, sep=' ', quotechar=' ', header=None, index=None, mode='a')
23912391

23922392
# make a lookup for lining up the necessary files to
@@ -2397,7 +2397,7 @@ def write_hfb_zone_multipliers_template(m):
23972397
ofp.write('{0},{1},{2}\n'.format(
23982398
os.path.join(m.model_ws, 'hfb6_org', m.hfb6.file_name[0]),
23992399
os.path.join(m.model_ws, 'hfb6_mlt',
2400-
os.path.basename(tpl_file).replace('.tpl','')),
2400+
os.path.basename(tpl_file).replace('.tpl', '')),
24012401
hfb_file))
24022402

24032403
return hfb_mults, tpl_file

pyemu/utils/helpers.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,31 +3600,34 @@ def apply_list_pars():
36003600
fmts += " %9G"
36013601
np.savetxt(os.path.join(model_ext_path, fname), df_list.loc[:, names].values, fmt=fmts)
36023602

3603-
def apply_hfb_pars():
3603+
def apply_hfb_pars(par_file='hfb6_pars.csv'):
36043604
""" a function to apply HFB multiplier parameters. Used to implement
36053605
the parameterization constructed by write_hfb_zone_multipliers_template()
36063606
3607-
This is to account for the horrible HFB6 format that differs from other BCs making this a special case
3607+
This is to account for the horrible HFB6 format that differs from other
3608+
BCs making this a special case
36083609
36093610
Note
36103611
----
36113612
requires "hfb_pars.csv"
36123613
36133614
should be added to the forward_run.py script
36143615
"""
3615-
hfb_pars = pd.read_csv('hfb6_pars.csv')
3616+
hfb_pars = pd.read_csv(par_file)
36163617

36173618
hfb_mults_contents = open(hfb_pars.mlt_file.values[0], 'r').readlines()
3618-
skiprows = sum([1 if i.strip().startswith('#') else 0 for i in hfb_mults_contents]) + 1
3619+
skiprows = sum([1 if i.strip().startswith('#') else 0
3620+
for i in hfb_mults_contents]) + 1
36193621
header = hfb_mults_contents[:skiprows]
36203622

36213623
# read in the multipliers
36223624
names = ['lay', 'irow1','icol1','irow2','icol2', 'hydchr']
3623-
hfb_mults = pd.read_csv(hfb_pars.mlt_file.values[0], skiprows=skiprows, delim_whitespace=True, names=names).dropna()
3624-
3625+
hfb_mults = pd.read_csv(hfb_pars.mlt_file.values[0], skiprows=skiprows,
3626+
delim_whitespace=True, names=names).dropna()
36253627

36263628
# read in the original file
3627-
hfb_org = pd.read_csv(hfb_pars.org_file.values[0], skiprows=skiprows, delim_whitespace=True, names=names).dropna()
3629+
hfb_org = pd.read_csv(hfb_pars.org_file.values[0], skiprows=skiprows,
3630+
delim_whitespace=True, names=names).dropna()
36283631

36293632
# multiply it out
36303633
hfb_org.hydchr *= hfb_mults.hydchr
@@ -3633,11 +3636,12 @@ def apply_hfb_pars():
36333636
hfb_mults[cn] = hfb_mults[cn].astype(np.int)
36343637
hfb_org[cn] = hfb_org[cn].astype(np.int)
36353638
# write the results
3636-
with open(hfb_pars.model_file.values[0], 'w') as ofp:
3639+
with open(hfb_pars.model_file.values[0], 'w', newline='') as ofp:
36373640
[ofp.write('{0}\n'.format(line.strip())) for line in header]
3641+
ofp.flush()
3642+
hfb_org[['lay', 'irow1', 'icol1', 'irow2', 'icol2', 'hydchr']].to_csv(
3643+
ofp, sep=' ', header=None, index=None)
36383644

3639-
hfb_org[['lay', 'irow1','icol1','irow2','icol2', 'hydchr']].to_csv(ofp, sep=' ',
3640-
header=None, index=None)
36413645

36423646
def write_const_tpl(name, tpl_file, suffix, zn_array=None, shape=None, spatial_reference=None,
36433647
longnames=False):

0 commit comments

Comments
 (0)