Skip to content

Commit 58eca97

Browse files
committed
Merge branch 'develop' into hotfix_hfb_pd_lineend
2 parents 02c0284 + b856e93 commit 58eca97

File tree

3 files changed

+43
-29
lines changed

3 files changed

+43
-29
lines changed

autotest/utils_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1661,7 +1661,7 @@ def fieldgen_dev():
16611661

16621662

16631663
if __name__ == "__main__":
1664-
# fieldgen_dev()
1664+
#fieldgen_dev()
16651665
# smp_test()
16661666
# smp_dateparser_test()
16671667
# smp_to_ins_test()

pyemu/utils/gw_utils.py

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,8 +1855,9 @@ def apply_sfr_obs():
18551855

18561856

18571857
def load_sfr_out(sfr_out_file, selection=None):
1858-
"""load an ASCII SFR output file into a dictionary of kper: dataframes. aggregates
1859-
flow to aquifer for segments and returns and flow out at downstream end of segment.
1858+
"""load an ASCII SFR output file into a dictionary of kper: dataframes.
1859+
aggregates flow to aquifer for segments and returns and flow out at
1860+
downstream end of segment.
18601861
18611862
Parameters
18621863
----------
@@ -1877,10 +1878,13 @@ def load_sfr_out(sfr_out_file, selection=None):
18771878
if selection is None:
18781879
pass
18791880
elif isinstance(selection, str):
1880-
assert selection == 'all', "If string passed as selection only 'all' allowed: {}".format(selection)
1881+
assert selection == 'all', \
1882+
"If string passed as selection only 'all' allowed: " \
1883+
"{}".format(selection)
18811884
else:
1882-
assert isinstance(
1883-
selection, pd.DataFrame), "'selection needs to be pandas Dataframe. Type {} passed.".format(type(selection))
1885+
assert isinstance(selection, pd.DataFrame), \
1886+
"'selection needs to be pandas Dataframe. " \
1887+
"Type {} passed.".format(type(selection))
18841888
assert np.all([sr in selection.columns for sr in ['segment', 'reach']]
18851889
), "Either 'segment' or 'reach' not in selection columns"
18861890
with open(sfr_out_file) as f:
@@ -1905,34 +1909,47 @@ def load_sfr_out(sfr_out_file, selection=None):
19051909
dlines.append(draw)
19061910
df = pd.DataFrame(data=np.array(dlines)).iloc[:, [3, 4, 6, 7]]
19071911
df.columns = ["segment", "reach", "flaqx", "flout"]
1908-
df.loc[:, "segment"] = df.segment.apply(np.int)
1909-
df.loc[:, "reach"] = df.reach.apply(np.int)
1910-
df.loc[:, "flaqx"] = df.flaqx.apply(np.float)
1911-
df.loc[:, "flout"] = df.flout.apply(np.float)
1912-
df.index = df.apply(lambda x: "{0:03d}_{1:03d}".format(int(x.segment), int(x.reach)), axis=1)
1912+
df["segment"] = df.segment.astype(np.int)
1913+
df["reach"] = df.reach.astype(np.int)
1914+
df["flaqx"] = df.flaqx.astype(np.float)
1915+
df["flout"] = df.flout.astype(np.float)
1916+
df.index = ["{0:03d}_{1:03d}".format(s, r) for s, r in
1917+
np.array([df.segment.values, df.reach.values]).T]
1918+
# df.index = df.apply(
1919+
# lambda x: "{0:03d}_{1:03d}".format(
1920+
# int(x.segment), int(x.reach)), axis=1)
19131921
if selection is None: # setup for all segs, aggregate
19141922
gp = df.groupby(df.segment)
19151923
bot_reaches = gp[['reach']].max().apply(
1916-
lambda x: "{0:03d}_{1:03d}".format(int(x.name), int(x.reach)), axis=1)
1917-
df2 = pd.DataFrame(index=gp.groups.keys(), columns=['flaqx', 'flout'])
1918-
df2['flaqx'] = gp.flaqx.sum() # only sum distributed output
1919-
df2['flout'] = df.loc[bot_reaches, 'flout'].values # take flow out of seg
1924+
lambda x: "{0:03d}_{1:03d}".format(
1925+
int(x.name), int(x.reach)), axis=1)
1926+
# only sum distributed output # take flow out of seg
1927+
df2 = pd.DataFrame(
1928+
{'flaqx':gp.flaqx.sum(),
1929+
'flout': df.loc[bot_reaches, 'flout'].values},
1930+
index=gp.groups.keys())
19201931
# df = df.groupby(df.segment).sum()
1921-
df2.loc[:,"segment"] = df2.index
1932+
df2["segment"] = df2.index
19221933
elif isinstance(selection, str) and selection == 'all':
19231934
df2 = df
19241935
else:
1925-
seg_reach_id = selection.apply(lambda x: "{0:03d}_{1:03d}".
1926-
format(int(x.segment), int(x.reach)), axis=1).values
1936+
seg_reach_id = selection.apply(
1937+
lambda x: "{0:03d}_{1:03d}".format(
1938+
int(x.segment), int(x.reach)), axis=1).values
19271939
for sr in seg_reach_id:
19281940
if sr not in df.index:
19291941
s, r = [x.lstrip('0') for x in sr.split('_')]
1930-
warnings.warn("Requested segment reach pair ({0},{1}) is not in sfr output. Dropping...".
1931-
format(int(r), int(s)), PyemuWarning)
1932-
seg_reach_id = np.delete(seg_reach_id, np.where(seg_reach_id == sr), axis=0)
1942+
warnings.warn(
1943+
"Requested segment reach pair ({0},{1}) "
1944+
"is not in sfr output. Dropping...".format(
1945+
int(r), int(s)), PyemuWarning)
1946+
seg_reach_id = np.delete(
1947+
seg_reach_id,
1948+
np.where(seg_reach_id == sr), axis=0)
19331949
df2 = df.loc[seg_reach_id].copy()
19341950
if kper in sfr_dict.keys():
1935-
print("multiple entries found for kper {0}, replacing...".format(kper))
1951+
print("multiple entries found for kper {0}, "
1952+
"replacing...".format(kper))
19361953
sfr_dict[kper] = df2
19371954
return sfr_dict
19381955

pyemu/utils/helpers.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,8 +3600,7 @@ 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-
3604-
def apply_hfb_pars(par_file='hfb6_pars.csv'):
3603+
def apply_hfb_pars():
36053604
""" a function to apply HFB multiplier parameters. Used to implement
36063605
the parameterization constructed by write_hfb_zone_multipliers_template()
36073606
@@ -3613,7 +3612,7 @@ def apply_hfb_pars(par_file='hfb6_pars.csv'):
36133612
36143613
should be added to the forward_run.py script
36153614
"""
3616-
hfb_pars = pd.read_csv(par_file)
3615+
hfb_pars = pd.read_csv('hfb6_pars.csv')
36173616

36183617
hfb_mults_contents = open(hfb_pars.mlt_file.values[0], 'r').readlines()
36193618
skiprows = sum([1 if i.strip().startswith('#') else 0 for i in hfb_mults_contents]) + 1
@@ -3636,11 +3635,9 @@ def apply_hfb_pars(par_file='hfb6_pars.csv'):
36363635
# write the results
36373636
with open(hfb_pars.model_file.values[0], 'w') as ofp:
36383637
[ofp.write('{0}\n'.format(line.strip())) for line in header]
3639-
ofp.flush()
3638+
36403639
hfb_org[['lay', 'irow1','icol1','irow2','icol2', 'hydchr']].to_csv(ofp, sep=' ',
3641-
header=None, index=None, mode='a', line_terminator='\n')
3642-
# hfb_org[['lay', 'irow1', 'icol1', 'irow2', 'icol2', 'hydchr']].to_csv(os.path.join('temp', 'test.csv'), sep=' ',
3643-
# header=None, index=None)
3640+
header=None, index=None)
36443641

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

0 commit comments

Comments
 (0)