Skip to content

Commit

Permalink
Fix(SfrFile): Update SfrFile for streambed elevation when present (#866)
Browse files Browse the repository at this point in the history
* Fix(SfrFile): Update SfrFile to include dataframe column for streambed elevation when present

* fix test_SfrFile for travis runs
  • Loading branch information
jlarsen-usgs committed May 4, 2020
1 parent a177d59 commit 4100de2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
20 changes: 18 additions & 2 deletions autotest/t009_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,22 @@ def test_SfrFile():
assert df.gradient.values[-1] == 5.502E-02
assert df.shape == (1080, 20)

ml = flopy.modflow.Modflow.load('test1tr.nam',
model_ws=path, exe_name='mf2005')
ml.change_model_ws(outpath)
ml.write_input()
ml.run_model()

sfrout = SfrFile(os.path.join(outpath, 'test1tr.flw'))
assert sfrout.ncol == 16, sfrout.ncol
assert sfrout.names == common_names + ['gradient'], sfrout.names
expected_times = [
(0, 0), (4, 0), (9, 0), (12, 0), (14, 0), (19, 0), (24, 0), (29, 0),
(32, 0), (34, 0), (39, 0), (44, 0), (49, 0), (0, 1), (4, 1), (9, 1),
(12, 1), (14, 1), (19, 1), (24, 1), (29, 1), (32, 1), (34, 1), (39, 1),
(44, 1), (45, 1), (46, 1), (47, 1), (48, 1), (49, 1)]
assert sfrout.times == expected_times, sfrout.times


def test_sfr_plot():
#m = flopy.modflow.Modflow.load('test1ss.nam', model_ws=path, verbose=False)
Expand All @@ -567,13 +583,13 @@ def test_sfr_plot():
if __name__ == '__main__':
# test_sfr()
# test_ds_6d_6e_disordered()
test_disordered_reachdata_fields()
# test_disordered_reachdata_fields()
# test_sfr_renumbering()
# test_example()
# test_export()
# test_transient_example()
# mtest_sfr_plot()
# test_assign_layers()
# test_SfrFile()
test_SfrFile()
# test_const()
pass
Binary file modified examples/data/mf6/test003_gwfs_disv/test003_gwfs_disv.dbf
Binary file not shown.
7 changes: 7 additions & 0 deletions flopy/utils/sfroutputfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ def __init__(self, filename, geometries=None, verbose=False):
evaluated_format = False
has_gradient = False
has_delUzstor = False
has_elevation = False
with open(self.filename) as f:
for i, line in enumerate(f):
if 'GRADIENT' in line:
has_gradient = True
if 'CHNG. UNSAT.' in line:
has_delUzstor = True
if 'ELEVATION' in line:
has_elevation = True
items = line.strip().split()
if len(items) > 0 and items[0].isdigit():
evaluated_format = True
Expand All @@ -90,6 +93,8 @@ def __init__(self, filename, geometries=None, verbose=False):
self.names += ['Qwt', 'delUzstor']
if self.ncol == 18:
self.names.append('gw_head')
if has_elevation:
self.names.append("strtop")
self.times = self.get_times()
self.geoms = None # not implemented yet
self._df = None
Expand Down Expand Up @@ -151,9 +156,11 @@ def get_dataframe(self):
header=None, names=self.names,
error_bad_lines=False,
skiprows=self.sr, low_memory=False)

# drop text between stress periods; convert to numeric
df['layer'] = self.pd.to_numeric(df.layer, errors='coerce')
df.dropna(axis=0, inplace=True)

# convert to proper dtypes
for c in df.columns:
df[c] = df[c].astype(self.dtypes.get(c, float))
Expand Down

0 comments on commit 4100de2

Please sign in to comment.