Skip to content

Commit

Permalink
Fix(MF6Output): fix add new obs package issue (#1193)
Browse files Browse the repository at this point in the history
* update MF6Output gwt list() method to use MfListBudget
* Added test to t504_test.py for adding new observations
  • Loading branch information
jlarsen-usgs authored Aug 17, 2021
1 parent feea04e commit 0d9faa3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
35 changes: 35 additions & 0 deletions autotest/t504_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,40 @@ def test_mf6_output():
raise AssertionError()


def test_mf6_output_add_observation():
model_name = "lakeex2a"
sim_ws = os.path.join("..", "examples", "data", "mf6", "test045_lake2tr")
sim = flopy.mf6.MFSimulation.load(sim_ws=sim_ws, exe_name=exe_name)
gwf = sim.get_model(model_name)

# remove sfr_obs and add a new sfr obs
sfr = gwf.sfr

obs_file = "{}.sfr.obs".format(model_name)
csv_file = obs_file + ".csv"
obs_dict = {
csv_file: [
("l08_stage", "stage", (8,)),
("l09_stage", "stage", (9,)),
("l14_stage", "stage", (14,)),
("l15_stage", "stage", (15,)),
]
}
gwf.sfr.obs.initialize(
filename=obs_file, digits=10, print_input=True, continuous=obs_dict
)

sim.simulation_data.mfpath.set_sim_path(cpth)
sim.write_simulation()
sim.run_simulation()

# check that .output finds the newly added OBS package
sfr_obs = gwf.sfr.output.obs()

if not isinstance(sfr_obs, flopy.utils.Mf6Obs):
raise TypeError("remove and add observation test (Mf6Output) failed")


if __name__ == "__main__":
test001a_tharmonic()
test001e_uzf_3lay()
Expand All @@ -1249,3 +1283,4 @@ def test_mf6_output():
test_cbc_precision()
test_replace_ims_package()
test_mf6_output()
test_mf6_output_add_observation()
29 changes: 23 additions & 6 deletions flopy/mf6/utils/output_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
ZoneBudget6,
ZoneFile6,
MfListBudget,
MtListBudget,
)
from ...utils.observationfile import CsvFile
from ...pakbase import PackageInterface
Expand Down Expand Up @@ -101,6 +100,28 @@ def __init__(self, obj):
if str(ky[-2]).lower() == "fileout":
data = [[ky[-1]]]
break
elif (
str(ky[-3]) == "continuous"
and str(ky[-1]) == "output"
):
if (
obj._simulation_data.mfdata[
ky
].array[0][0]
== "fileout"
):
data = [
[
obj._simulation_data.mfdata[
ky
].array[
0
][
-2
]
]
]
break

if rectype == "package_convergence":
rectype = "csv"
Expand Down Expand Up @@ -301,13 +322,9 @@ def __list(self):
MfListBudget, MtListBudget object
"""
if self._lst is not None:
reader = MfListBudget
if self._mtype == "gwt":
reader = MtListBudget

try:
list_file = os.path.join(self._sim_ws, self._lst)
return reader(list_file)
return MfListBudget(list_file)
except (AssertionError, IOError, FileNotFoundError):
return None

Expand Down

0 comments on commit 0d9faa3

Please sign in to comment.