From 2918494f3731bbf58697f635127de66df63b5273 Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Mon, 16 Aug 2021 18:33:04 -0700 Subject: [PATCH] Fix(MF6Output): fix add new obs package issue * update MF6Output gwt list() method to use MfListBudget * Added test to t504_test.py for adding new observations --- autotest/t504_test.py | 35 ++++++++++++++++++++++++++++++++++ flopy/mf6/utils/output_util.py | 29 ++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/autotest/t504_test.py b/autotest/t504_test.py index 57798d0e44..8e5b42ca8a 100644 --- a/autotest/t504_test.py +++ b/autotest/t504_test.py @@ -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() @@ -1249,3 +1283,4 @@ def test_mf6_output(): test_cbc_precision() test_replace_ims_package() test_mf6_output() + test_mf6_output_add_observation() diff --git a/flopy/mf6/utils/output_util.py b/flopy/mf6/utils/output_util.py index a73ce3e850..900aaf9e55 100644 --- a/flopy/mf6/utils/output_util.py +++ b/flopy/mf6/utils/output_util.py @@ -6,7 +6,6 @@ ZoneBudget6, ZoneFile6, MfListBudget, - MtListBudget, ) from ...utils.observationfile import CsvFile from ...pakbase import PackageInterface @@ -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" @@ -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