Skip to content

Commit

Permalink
fix:(#830): handling 'none' cellids in SFR package (#834)
Browse files Browse the repository at this point in the history
* fix(#830): handling 'none' in SFR package

* fix(#830): handling 'none' in sfr package

* fix(#830): added test case with cellid 'none'

* fix(#830)

* fix(#830): updated data for sfr cellid 'none' test

* fix(#830)
  • Loading branch information
spaulins-usgs committed Mar 25, 2020
1 parent 1284871 commit 4bfab91
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
9 changes: 8 additions & 1 deletion autotest/t505_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ def test028_sfr():
os.path.join(pth, 'sfr_reach_per_rec.txt'))
# test zero based indexes
reach_con_rec[0] = (0, -0.0)
sfr_package = ModflowGwfsfr(model, unit_conversion=1.486,
sfr_package = ModflowGwfsfr(model, unit_conversion=1.486,
stage_filerecord='test1tr.sfr.stage.bin',
budget_filerecord='test1tr.sfr.cbc',
nreaches=36, packagedata=sfr_rec,
Expand All @@ -1690,6 +1690,7 @@ def test028_sfr():
assert (sfr_package.connectiondata.get_data()[0][1] == -0.0)
assert (sfr_package.connectiondata.get_data()[1][1] == 0.0)
assert (sfr_package.connectiondata.get_data()[2][1] == 1.0)
assert (sfr_package.packagedata.get_data()[1][1].lower() == 'none')

sim.simulation_data.mfpath.set_sim_path(run_folder)
sim.write_simulation()
Expand All @@ -1700,11 +1701,17 @@ def test028_sfr():
assert (sfr_package.connectiondata.get_data()[0][1] == -0.0)
assert (sfr_package.connectiondata.get_data()[1][1] == 0.0)
assert (sfr_package.connectiondata.get_data()[2][1] == 1.0)
assert (sfr_package.packagedata.get_data()[1][1].lower() == 'none')

# undo zero based test and move on
model.remove_package(sfr_package.package_type)
reach_con_rec = testutils.read_reach_con_rec(
os.path.join(pth, 'sfr_reach_con_rec.txt'))

# set sfr settings back to expected package data
rec_line = (sfr_rec[1][0], (0, 1, 1)) + sfr_rec[1][2:]
sfr_rec[1] = rec_line

sfr_package = ModflowGwfsfr(model, unit_conversion=1.486,
stage_filerecord='test1tr.sfr.stage.bin',
budget_filerecord='test1tr.sfr.cbc',
Expand Down
2 changes: 1 addition & 1 deletion examples/data/mf6/create_tests/test028_sfr/sfr_rec.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 1 1 1 4500. 12 8.6767896E-04 1093.048 3.0 0.00003 0.03 1 1.0 0
2 1 2 2 7000. 12 8.6767896E-04 1088.059 3.0 0.00003 0.03 2 1.0 0
2 None 7000. 12 8.6767896E-04 1088.059 3.0 0.00003 0.03 2 1.0 0
3 1 3 3 6000. 12 8.6767896E-04 1082.419 3.0 0.00003 0.03 2 1.0 0
4 1 3 4 5550. 12 8.6767896E-04 1077.408 3.0 0.00003 0.03 3 1.0 1
5 1 4 5 6500. 12 9.4339624E-04 1071.934 3.0 0.00003 0.03 2 1.0 0
Expand Down
3 changes: 2 additions & 1 deletion flopy/mf6/data/mfdatastorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,8 @@ def _verify_list(self, data):
cellid_size = model_grid.\
get_num_spatial_coordinates()
if cellid_size != 1 and \
len(data_line[index]) != cellid_size:
len(data_line[index]) != cellid_size and \
isinstance(data_line[index], int):
message = 'Cellid "{}" contains {} integer(s). ' \
'Expected a cellid containing {} ' \
'integer(s) for grid type' \
Expand Down
12 changes: 8 additions & 4 deletions flopy/mf6/data/mfdatautil.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ def to_string(val, data_type, sim_data, data_dim, is_cellid=False,
elif is_cellid or (possible_cellid and isinstance(val, tuple)):
if DatumUtil.is_int(val):
return str(val + 1)
if len(val) > 0 and val[0] == 'none':
if len(val) > 0 and isinstance(val, str) and \
val.lower() == 'none':
# handle case that cellid is 'none'
return val[0]
return val
if is_cellid and \
data_dim.get_model_dim(None).model_name is not \
None:
Expand All @@ -148,8 +149,11 @@ def to_string(val, data_type, sim_data, data_dim, is_cellid=False,
sim_data.debug)

string_val = []
for item in val:
string_val.append(str(item + 1))
if isinstance(val, str):
string_val.append(val)
else:
for item in val:
string_val.append(str(item + 1))
return ' '.join(string_val)
elif data_type == DatumType.integer:
if data_item is not None and data_item.numeric_index:
Expand Down
2 changes: 2 additions & 0 deletions flopy/mf6/data/mffileaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,8 @@ def read_list_data_from_file(self, file_handle, storage, current_key,
True)
storage.data_dimensions.unlock()
return data_rec
self.simple_line = self.simple_line \
and self.structure.package_type != 'sfr'
if self.simple_line:
line_len = len(self._last_line_info)
if struct.num_optional > 0 and not line_info_processed:
Expand Down
28 changes: 17 additions & 11 deletions flopy/mf6/utils/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,24 @@ def read_sfr_rec(sfr_file, cellid_size=3):
sfrrecarray = []
for line in fd:
fd_spl = line.strip().split()
try:
cellid = make_int_tuple(fd_spl[1:1+cellid_size])
temp_size = cellid_size
except ValueError:
cellid = fd_spl[1]
temp_size = 1
sfrrecarray.append((int(fd_spl[0]) - 1,
make_int_tuple(fd_spl[1:1+cellid_size]),
float(fd_spl[cellid_size+1]),
int(fd_spl[cellid_size+2]),
float(fd_spl[cellid_size+3]),
float(fd_spl[cellid_size+4]),
float(fd_spl[cellid_size+5]),
float(fd_spl[cellid_size+6]),
float(fd_spl[cellid_size+7]),
int(fd_spl[cellid_size+8]),
float(fd_spl[cellid_size+9]),
int(fd_spl[cellid_size+10])))
cellid,
float(fd_spl[temp_size+1]),
int(fd_spl[temp_size+2]),
float(fd_spl[temp_size+3]),
float(fd_spl[temp_size+4]),
float(fd_spl[temp_size+5]),
float(fd_spl[temp_size+6]),
float(fd_spl[temp_size+7]),
int(fd_spl[temp_size+8]),
float(fd_spl[temp_size+9]),
int(fd_spl[temp_size+10])))
fd.close()
return sfrrecarray

Expand Down

0 comments on commit 4bfab91

Please sign in to comment.