Skip to content

Commit

Permalink
feat(mf6 checker): input data check for mf6 (#779)
Browse files Browse the repository at this point in the history
* feat(input data check for mf6): refactored mf2005 input data check to support both mf2005 and mf6

* feat(input data check for mf6): refactor of mf2005 code to work with mf6

* feat(input data check for mf6): autotest updates

* feat(input data check for mf6)

* fix(codacy fixes)

* fix(check too complex)

* fix(codacy): simplified check code
  • Loading branch information
spaulins-usgs authored and langevin-usgs committed Jan 16, 2020
1 parent 73f7051 commit 088f147
Show file tree
Hide file tree
Showing 30 changed files with 920 additions and 420 deletions.
1 change: 1 addition & 0 deletions autotest/t024_test.py
Expand Up @@ -40,6 +40,7 @@ def test_bcs_check():
ibound[1, 1, 1] = 1 # fully isolated cell
ibound[0:2, 4, 4] = 1 # cell connected vertically to one other cell
bas = flopy.modflow.ModflowBas(mf, ibound=ibound)
mf._mg_resync = True
chk = bas.check()
assert chk.summary_array['desc'][0] == 'isolated cells in ibound array'
assert chk.summary_array.i[0] == 1 and chk.summary_array.i[0] == 1 and \
Expand Down
27 changes: 17 additions & 10 deletions autotest/t504_test.py
Expand Up @@ -49,7 +49,7 @@ def test001a_tharmonic():

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verbosity_level=0)
verbosity_level=0, verify_data=True)
sim.simulation_data.mfpath.set_sim_path(run_folder)

# write simulation to new location
Expand Down Expand Up @@ -150,7 +150,8 @@ def test003_gwfs_disv():
array_util = PyListUtil()

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verify_data=True)

# make temp folder to save simulation
sim.simulation_data.mfpath.set_sim_path(run_folder)
Expand Down Expand Up @@ -235,7 +236,7 @@ def test005_advgw_tidal():

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verbosity_level=2)
verbosity_level=2, verify_data=True)

# test obs/ts package interface
model = sim.get_model(model_name)
Expand Down Expand Up @@ -321,7 +322,8 @@ def test006_gwf3():
array_util = PyListUtil()

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verify_data=True)

model = sim.get_model()
disu = model.get_package('disu')
Expand Down Expand Up @@ -460,7 +462,8 @@ def test045_lake1ss_table():
expected_head_file_b = os.path.join(expected_output_folder, 'lakeex1b_adj.hds')

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verify_data=True)

# make temp folder to save simulation
sim.simulation_data.mfpath.set_sim_path(run_folder)
Expand Down Expand Up @@ -532,7 +535,7 @@ def test006_2models_mvr():
expected_head_file_bb = os.path.join(expected_output_folder, 'model2_adj.hds')

# load simulation
sim = MFSimulation.load(sim_name, 'mf6', exe_name, pth)
sim = MFSimulation.load(sim_name, 'mf6', exe_name, pth, verify_data=True)

# make temp folder to save simulation
sim.simulation_data.mfpath.set_sim_path(run_folder)
Expand Down Expand Up @@ -685,7 +688,8 @@ def test001e_uzf_3lay():
expected_head_file_b = os.path.join(expected_output_folder, 'test001e_UZF_3lay_adj.hds')

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verify_data=True)

# make temp folder to save simulation
sim.simulation_data.mfpath.set_sim_path(run_folder)
Expand Down Expand Up @@ -766,7 +770,8 @@ def test045_lake2tr():
'lakeex2a_adj.hds')

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verify_data=True)

# write simulation to new location
sim.simulation_data.mfpath.set_sim_path(run_folder)
Expand Down Expand Up @@ -824,7 +829,8 @@ def test036_twrihfb():
expected_head_file_b = os.path.join(expected_output_folder, 'twrihfb2015_output_adj.hds')

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verify_data = True)

# make temp folder to save simulation
sim.simulation_data.mfpath.set_sim_path(run_folder)
Expand Down Expand Up @@ -890,7 +896,8 @@ def test027_timeseriestest():
expected_head_file_b = os.path.join(expected_output_folder, 'timeseriestest_adj.hds')

# load simulation
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth)
sim = MFSimulation.load(model_name, 'mf6', exe_name, pth,
verify_data=True)

# make temp folder to save simulation
sim.simulation_data.mfpath.set_sim_path(run_folder)
Expand Down
46 changes: 41 additions & 5 deletions autotest/t505_test.py
Expand Up @@ -74,8 +74,8 @@ def np001():
exe_name=exe_name, sim_ws=run_folder,
continue_=True, memory_print_option='summary')
name = test_sim.name_file
assert name.continue_.get_data() == True
assert name.nocheck.get_data() == None
assert name.continue_.get_data()
assert name.nocheck.get_data() is None
assert name.memory_print_option.get_data() == 'summary'

kwargs = {}
Expand Down Expand Up @@ -289,8 +289,25 @@ def np001():
stress_period_data=well_spd)
except MFDataException:
error_occurred = True

assert error_occurred

# test error checking
drn_package = ModflowGwfdrn(model, print_input=True, print_flows=True,
save_flows=True, maxbound=1,
timeseries=[(0.0, 60.0), (100000.0, 60.0)],
stress_period_data=[((100, 0, 0), np.nan,
'drn_1'), ((0, 0, 0),
10.0)])
npf_package = ModflowGwfnpf(model, save_flows=True,
alternative_cell_averaging='logarithmic',
icelltype=1, k=100001.0, k33=1e-12)
chk = sim.check()
summary = '.'.join(chk[0].summary_array.desc)
assert 'drn_1 package: invalid BC index' in summary
assert 'npf package: vertical hydraulic conductivity values below ' \
'checker threshold of 1e-11' in summary
assert 'npf package: horizontal hydraulic conductivity values above ' \
'checker threshold of 100000.0' in summary
return


Expand Down Expand Up @@ -391,8 +408,8 @@ def np002():
sim.run_simulation()

sim2 = MFSimulation.load(sim_ws=run_folder)
model = sim2.get_model(model_name)
npf_package = model.get_package('npf')
model_ = sim2.get_model(model_name)
npf_package = model_.get_package('npf')
k = npf_package.k.array

# get expected results
Expand Down Expand Up @@ -426,6 +443,20 @@ def np002():
# clean up
sim.delete_output_files()

# test error checking
sto_package = ModflowGwfsto(model, save_flows=True, iconvert=1,
ss=0.00000001, sy=0.6)
chd_package = ModflowGwfchd(model, print_input=True, print_flows=True,
maxbound=1, stress_period_data=[((0, 0, 0),
np.nan)])
chk = sim.check()
summary = '.'.join(chk[0].summary_array.desc)
assert 'sto package: specific storage values below ' \
'checker threshold of 1e-06' in summary
assert 'sto package: specific yield values above ' \
'checker threshold of 0.5' in summary
assert 'Not a number' in summary

return


Expand Down Expand Up @@ -954,6 +985,11 @@ def test005_advgw_tidal():
# clean up
sim.delete_output_files()

# check packages
chk = sim.check()
summary = '.'.join(chk[0].summary_array.desc)
assert summary == ''

return


Expand Down
10 changes: 10 additions & 0 deletions flopy/discretization/structuredgrid.py
Expand Up @@ -55,9 +55,15 @@ def __init__(self, delc=None, delr=None, top=None, botm=None, idomain=None,
assert self.__nrow * self.__ncol == len(np.ravel(top))
if botm is not None:
assert self.__nrow * self.__ncol == len(np.ravel(botm[0]))
if nlay is not None and nlay < len(botm):
self.__nlay_nocbd = nlay
else:
self.__nlay_nocbd = len(botm)

self.__nlay = len(botm)
else:
self.__nlay = nlay
self.__nlay_nocbd = nlay

####################
# Properties
Expand All @@ -75,6 +81,10 @@ def is_complete(self):
return True
return False

@property
def nlay_nocbd(self):
return self.__nlay_nocbd

@property
def nlay(self):
return self.__nlay
Expand Down
7 changes: 6 additions & 1 deletion flopy/discretization/unstructuredgrid.py
Expand Up @@ -96,11 +96,16 @@ def nnodes(self):
@property
def ncpl(self):
if self._ncpl is None:
return len(self._iverts)
if self._iverts is None:
return None
else:
return len(self._iverts)
return self._ncpl

@property
def shape(self):
if self.ncpl is None:
return self.nnodes
if isinstance(self.ncpl, (list, np.ndarray)):
return self.nlay, self.ncpl[0]
else:
Expand Down
3 changes: 2 additions & 1 deletion flopy/export/netcdf.py
Expand Up @@ -197,7 +197,8 @@ def __init__(self, output_filename, model, time_values=None,
self.z_positive = z_positive
if self.grid_units is None:
self.grid_units = "unspecified"
assert self.grid_units in ["feet", "meters", "unspecified"], \
assert self.grid_units in ["feet", "meters", "unspecified",
"undefined"], \
"unsupported length units: " + self.grid_units

self.time_units = self.model_time.time_units
Expand Down

0 comments on commit 088f147

Please sign in to comment.