Skip to content

Commit

Permalink
fix(mfsfr2.py): isfropt and icalc read/write logic (#723)
Browse files Browse the repository at this point in the history
* added unit tests covering all combinations of isfropt and icalc to t010_test.py
  • Loading branch information
jlarsen-usgs authored and langevin-usgs committed Nov 15, 2019
1 parent c7856a5 commit 9f06345
Show file tree
Hide file tree
Showing 66 changed files with 996 additions and 26 deletions.
37 changes: 32 additions & 5 deletions autotest/t010_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def load_check_sfr(i, mfnam, model_ws, checker_output_path):
m = flopy.modflow.Modflow.load(mfnam, model_ws=model_ws)
m.model_ws = checker_output_path
checker_outfile = os.path.join(tpth, 'SFRcheck_{}.txt'.format(m.name))

chk = m.sfr.check(checker_outfile, level=1)

if i == 1:
Expand All @@ -59,7 +59,7 @@ def test_sfrcheck():
m.model_ws= cpth
fpth = 'SFRchecker_results.txt'
m.sfr.check(fpth, level=0)

# test checks without modifications
chk = check(m.sfr)
chk.numbering()
Expand All @@ -73,11 +73,11 @@ def test_sfrcheck():
assert test in chk.passed
chk.slope()
assert 'minimum slope' in chk.passed

# create gaps in segment numbering
m.sfr.segment_data[0]['nseg'][-1] += 1
m.sfr.reach_data['ireach'][3] += 1

# create circular routing instance
m.sfr.segment_data[0]['outseg'][0] = 1
m.sfr._graph = None # weak, but the above shouldn't happen
Expand Down Expand Up @@ -111,15 +111,42 @@ def test_sfrcheck():
chk.elevations()
assert 'maximum streambed top' in chk.warnings
assert True


def test_sfrloadcheck():
for i, case in sfr_items.items():
yield load_check_sfr, i, case['mfnam'], path, cpth


def load_sfr_isfropt_icalc(isfropt, icalc):
pth = os.path.join("..", "examples", "data", "sfr_test")
nam = "sfrtest{}{}.nam".format(isfropt, icalc)
ml = flopy.modflow.Modflow.load(nam, check=False, model_ws=pth,
exe_name="mfnwt")
sfr = ml.get_package("SFR")
if sfr is None:
raise AssertionError()

ml.change_model_ws(tpth)
ml.write_input()
success = ml.run_model()[0]
if not success:
raise AssertionError("sfrtest{}{}.nam".format(isfropt, icalc) +
"is broken, please fix SFR 6a, 6bc logic!")


def test_isfropt_icalc():
# test all valid combinations of isfropt and icalc
for isfropt in range(6):
for icalc in range(5):
yield load_sfr_isfropt_icalc, isfropt, icalc


if __name__ == '__main__':
test_sfrcheck()
for i, case in sfr_items.items():
load_check_sfr(i, case['mfnam'], path, cpth)

for isfropt in range(6):
for icalc in range(5):
load_sfr_isfropt_icalc(isfropt, icalc)
4 changes: 4 additions & 0 deletions examples/data/sfr_test/sfrtest.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FREE
CONSTANT 1
-999
CONSTANT 1000.
9 changes: 9 additions & 0 deletions examples/data/sfr_test/sfrtest.dis
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1 10 10 3 4 2
0
CONSTANT 100
CONSTANT 100
CONSTANT 1000.
CONSTANT 0.
365 365 1. TR
365 365 1. TR
365 365 1. TR
1 change: 1 addition & 0 deletions examples/data/sfr_test/sfrtest.nwt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 10 2000 1E-007 2 1 1 COMPLEX CONTINUE
10 changes: 10 additions & 0 deletions examples/data/sfr_test/sfrtest.upw
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-1 -999.0 0 1
1
0
1
1
0
CONSTANT 2.0
CONSTANT 0.2
CONSTANT 1E-06
CONSTANT 0.1
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest00.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 7 sfrtest.upw
NWT 10 sfrtest.nwt
SFR 11 sfrtest00.sfr
23 changes: 23 additions & 0 deletions examples/data/sfr_test/sfrtest00.sfr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
10 1 0 0 86400.0 0.0001 -1 0 0 15 1 30
1 5 1 1 1 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 2 1 2 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 3 1 3 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 4 1 4 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 5 1 5 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 6 1 6 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 7 1 7 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 8 1 8 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 9 1 9 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 10 1 10 150 1000 0.1 2 45 0.3 0.25 5 10
1 1 1
1 0 0 0 100 50 0 0
45 5 1000 20 1
45 5 999 20 1
1 1 1
1 0 0 0 100 50 0 0
45 5 1000 20 1
45 5 999 20 1
1 1 1
1 0 0 0 100 50 0 0
45 5 1000 20 1
45 5 999 20 1
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest01.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 10 sfrtest.upw
SFR 11 sfrtest01.sfr
NWT 12 sfrtest.nwt
23 changes: 23 additions & 0 deletions examples/data/sfr_test/sfrtest01.sfr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
10 1 0 0 86400.0 0.0001 -1 0 0 15 1 30
1 5 1 1 1 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 2 1 2 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 3 1 3 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 4 1 4 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 5 1 5 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 6 1 6 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 7 1 7 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 8 1 8 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 9 1 9 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 10 1 10 150 1000 0.1 2 45 0.3 0.25 5 10
1 1 1
1 1 0 0 100 50 0 0 0.25
45 5 1000 20
45 5 999 20
1 1 1
1 1 0 0 100 50 0 0 0.25
45 5 1000 20
45 5 999 20
1 1 1
1 1 0 0 100 50 0 0 0.25
45 5 1000 20
45 5 999 20
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest02.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 10 sfrtest.upw
SFR 11 sfrtest02.sfr
NWT 12 sfrtest.nwt
29 changes: 29 additions & 0 deletions examples/data/sfr_test/sfrtest02.sfr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
10 1 0 0 86400.0 0.0001 -1 0 0 15 1 30
1 5 1 1 1 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 2 1 2 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 3 1 3 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 4 1 4 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 5 1 5 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 6 1 6 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 7 1 7 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 8 1 8 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 9 1 9 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 10 1 10 150 1000 0.1 2 45 0.3 0.25 5 10
1 1 1
1 2 0 0 100 50 0 0 0.25 0.50
45 5 1000
45 5 999
0.0 0.2 0.3 0.4 0.6 0.7 0.8 1.0
10 9 7 3 3 7 9 10
1 1 1
1 2 0 0 100 50 0 0 0.25 0.50
45 5 1000
45 5 999
0.0 0.2 0.3 0.4 0.6 0.7 0.8 1.0
10 9 7 3 3 7 9 10
1 1 1
1 2 0 0 100 50 0 0 0.25 0.50
45 5 1000
45 5 999
0.0 0.2 0.3 0.4 0.6 0.7 0.8 1.0
10 9 7 3 3 7 9 10
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest03.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 10 sfrtest.upw
SFR 11 sfrtest03.sfr
NWT 12 sfrtest.nwt
23 changes: 23 additions & 0 deletions examples/data/sfr_test/sfrtest03.sfr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
10 1 0 0 86400.0 0.0001 -1 0 0 15 1 30
1 5 1 1 1 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 2 1 2 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 3 1 3 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 4 1 4 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 5 1 5 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 6 1 6 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 7 1 7 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 8 1 8 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 9 1 9 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 10 1 10 150 1000 0.1 2 45 0.3 0.25 5 10
1 1 1
1 3 0 0 100 50 0 0 1 0.1 1 0.1
45 5 1000
45 5 999
1 1 1
1 3 0 0 100 50 0 0 1 0.1 1 0.1
45 5 1000
45 5 999
1 1 1
1 3 0 0 100 50 0 0 1 0.1 1 0.1
45 5 1000
45 5 999
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest04.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 10 sfrtest.upw
SFR 11 sfrtest04.sfr
NWT 12 sfrtest.nwt
32 changes: 32 additions & 0 deletions examples/data/sfr_test/sfrtest04.sfr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
10 1 0 0 86400.0 0.0001 -1 0 0 15 1 30
1 5 1 1 1 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 2 1 2 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 3 1 3 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 4 1 4 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 5 1 5 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 6 1 6 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 7 1 7 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 8 1 8 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 9 1 9 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 10 1 10 150 1000 0.1 2 45 0.3 0.25 5 10
1 1 1
1 4 0 0 2 100 50 0 0
45 5 1000
45 5 999
10 100
1 2
4 8
1 1 1
1 4 0 0 2 100 50 0 0
45 5 1000
45 5 999
10 100
1 2
4 8
1 1 1
1 4 0 0 2 100 50 0 0
45 5 1000
45 5 999
10 100
1 2
4 8
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest10.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 10 sfrtest.upw
SFR 11 sfrtest10.sfr
NWT 12 sfrtest.nwt
24 changes: 24 additions & 0 deletions examples/data/sfr_test/sfrtest10.sfr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
REACHINPUT
10 1 0 0 86400.0 0.0001 -1 0 1 15 1 30
1 5 1 1 1 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 2 1 2 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 3 1 3 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 4 1 4 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 5 1 5 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 6 1 6 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 7 1 7 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 8 1 8 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 9 1 9 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 10 1 10 150 1000 0.1 2 45 0.3 0.25 5 10
1 1 1
1 0 0 0 100 50 0 0
20 1
20 1
1 1 1
1 0 0 0 100 50 0 0
20 1
20 1
1 1 1
1 0 0 0 100 50 0 0
20 1
20 1
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest11.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 10 sfrtest.upw
SFR 11 sfrtest11.sfr
NWT 12 sfrtest.nwt
24 changes: 24 additions & 0 deletions examples/data/sfr_test/sfrtest11.sfr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
REACHINPUT
10 1 0 0 86400.0 0.0001 -1 0 1 15 1 30
1 5 1 1 1 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 2 1 2 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 3 1 3 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 4 1 4 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 5 1 5 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 6 1 6 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 7 1 7 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 8 1 8 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 9 1 9 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 10 1 10 150 1000 0.1 2 45 0.3 0.25 5 10
1 1 1
1 1 0 0 100 50 0 0 0.25
20
20
1 1 1
1 1 0 0 100 50 0 0 0.25
20
20
1 1 1
1 1 0 0 100 50 0 0 0.25
20
20
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest12.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 10 sfrtest.upw
SFR 11 sfrtest12.sfr
NWT 12 sfrtest.nwt
24 changes: 24 additions & 0 deletions examples/data/sfr_test/sfrtest12.sfr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
REACHINPUT
10 1 0 0 86400.0 0.0001 -1 0 1 15 1 30
1 5 1 1 1 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 2 1 2 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 3 1 3 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 4 1 4 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 5 1 5 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 6 1 6 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 7 1 7 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 8 1 8 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 9 1 9 150 1000 0.1 2 45 0.3 0.25 5 10
1 5 10 1 10 150 1000 0.1 2 45 0.3 0.25 5 10
1 1 1
1 2 0 0 100 50 0 0 0.25 0.50
0.0 0.2 0.3 0.4 0.6 0.7 0.8 1.0
10 9 7 3 3 7 9 10
1 1 1
1 2 0 0 100 50 0 0 0.25 0.50
0.0 0.2 0.3 0.4 0.6 0.7 0.8 1.0
10 9 7 3 3 7 9 10
1 1 1
1 2 0 0 100 50 0 0 0.25 0.50
0.0 0.2 0.3 0.4 0.6 0.7 0.8 1.0
10 9 7 3 3 7 9 10
6 changes: 6 additions & 0 deletions examples/data/sfr_test/sfrtest13.nam
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LIST 2 sfrtest.lst
BAS6 8 sfrtest.bas
DIS 9 sfrtest.dis
UPW 10 sfrtest.upw
SFR 11 sfrtest13.sfr
NWT 12 sfrtest.nwt
Loading

0 comments on commit 9f06345

Please sign in to comment.