From 1512dab52cf47461e914de0656762f9a17949c2b Mon Sep 17 00:00:00 2001 From: ConstableCatnip <38230539+ConstableCatnip@users.noreply.github.com> Date: Wed, 4 Dec 2019 16:35:51 -0700 Subject: [PATCH 1/6] fix(upw): keyword for vertical K The keyword for vertical K in mfupw.py was inconsistent with online documentation and mflpf.py. This was causing vertical Ks to be set to 0 when loading a model setup with parameters. --- flopy/modflow/mfupw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flopy/modflow/mfupw.py b/flopy/modflow/mfupw.py index c0893e9334..5635093113 100644 --- a/flopy/modflow/mfupw.py +++ b/flopy/modflow/mfupw.py @@ -433,14 +433,14 @@ def load(f, model, ext_unit_dict=None, check=True): if model.verbose: print(' loading vka layer {0:3d}...'.format(k + 1)) if 'vk' not in par_types and 'vani' not in par_types: - key = 'vka' + key = 'vk' if layvka[k] != 0: key = 'vani' t = Util2d.load(f, model, (nrow, ncol), np.float32, key, ext_unit_dict) else: line = f.readline() - key = 'vka' + key = 'vk' if 'vani' in par_types: key = 'vani' t = mfpar.parameter_fill(model, (nrow, ncol), key, parm_dict, From 608f0a3fec660685bca0c437c71e4dc4be6e4cc6 Mon Sep 17 00:00:00 2001 From: ConstableCatnip <38230539+ConstableCatnip@users.noreply.github.com> Date: Wed, 4 Dec 2019 16:40:16 -0700 Subject: [PATCH 2/6] fix(hob): fix multilayer proportion check error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix error message for layer proportion check with multilayer hobs. Currently “.format” only operates on the last line of the error message. --- flopy/modflow/mfhob.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flopy/modflow/mfhob.py b/flopy/modflow/mfhob.py index 7c1ee6058a..8d3034efae 100755 --- a/flopy/modflow/mfhob.py +++ b/flopy/modflow/mfhob.py @@ -577,9 +577,9 @@ def __init__(self, model, tomulth=1., obsname='HOBS', for key, value in self.mlay.items(): tot += value if not (np.isclose(tot, 1.0, rtol=0)): - msg = 'sum of dataset 4 proportions must equal 1.0 - ' + \ + msg = ('sum of dataset 4 proportions must equal 1.0 - ' + \ 'sum of dataset 4 proportions = {tot} for ' + \ - 'observation name {obsname}.'.format( + 'observation name {obsname}.').format( tot=tot, obsname=self.obsname) raise ValueError(msg) From 97d56a1c70aa41d840e758620777117c85a2086c Mon Sep 17 00:00:00 2001 From: ConstableCatnip <38230539+ConstableCatnip@users.noreply.github.com> Date: Tue, 10 Dec 2019 10:56:23 -0700 Subject: [PATCH 3/6] fix(upw): load() to be similar to lpf.load() Updated upw.load() function to be similar to that used in lpf.load(). Also removed a redundent, less robust keyword check for "vk" vs. "vani". Added example files to test loading upw with parameters and zones. --- autotest/t003_test.py | 15 +++++++++++ examples/data/parameters/twrip_upw.nam | 14 ++++++++++ examples/data/parameters/twrip_upw.nwt | 2 ++ examples/data/parameters/twrip_upw.pval | 6 +++++ examples/data/parameters/twrip_upw.upw | 35 +++++++++++++++++++++++++ examples/data/parameters/twrip_upw.zon | 20 ++++++++++++++ flopy/modflow/mfupw.py | 24 ++++++++++++----- 7 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 examples/data/parameters/twrip_upw.nam create mode 100644 examples/data/parameters/twrip_upw.nwt create mode 100644 examples/data/parameters/twrip_upw.pval create mode 100644 examples/data/parameters/twrip_upw.upw create mode 100644 examples/data/parameters/twrip_upw.zon diff --git a/autotest/t003_test.py b/autotest/t003_test.py index e547ad2147..714fecb116 100644 --- a/autotest/t003_test.py +++ b/autotest/t003_test.py @@ -44,6 +44,20 @@ def test_loadtwrip(): assert ml.load_fail is False return + + +def test_loadtwrip_upw(): + cwd = os.getcwd() + pth = os.path.join('..', 'examples', 'data', 'parameters') + assert (os.path.isdir(pth)) + os.chdir(pth) + namefile = 'twrip_upw.nam' + ml = flopy.modflow.Modflow.load(namefile, verbose=True) + os.chdir(cwd) + assert isinstance(ml, flopy.modflow.Modflow) + assert ml.load_fail is False + + return def test_loadoc(): @@ -116,3 +130,4 @@ def test_load_nam_mt_nonexistant_file(): test_loadfreyberg() test_loadoahu() test_loadtwrip() + test_loadtwrip_upw() diff --git a/examples/data/parameters/twrip_upw.nam b/examples/data/parameters/twrip_upw.nam new file mode 100644 index 0000000000..235b0b0b14 --- /dev/null +++ b/examples/data/parameters/twrip_upw.nam @@ -0,0 +1,14 @@ +LIST 2 twrip_upw.lst +BAS6 3 twrip.ba6 +PVAL 4 twrip_upw.pval +UPW 11 twrip_upw.upw +WEL 12 twrip.wel +DRN 13 twrip.drn +RCH 18 twrip.rch +NWT 19 twrip_upw.nwt +OC 22 twrip.oc +MULT 8 twrip.mlt +ZONE 9 twrip_upw.zon +DIS 10 twrip.dis +DATA 101 twrip.ib1.ref +DATA 102 rchzones.ref diff --git a/examples/data/parameters/twrip_upw.nwt b/examples/data/parameters/twrip_upw.nwt new file mode 100644 index 0000000000..9a037ce764 --- /dev/null +++ b/examples/data/parameters/twrip_upw.nwt @@ -0,0 +1,2 @@ +# NWT package for MODFLOW-NWT, generated by Flopy. + 1.000e-02 5.000e+02 100 1.000e-05 1 0 0 SIMPLE diff --git a/examples/data/parameters/twrip_upw.pval b/examples/data/parameters/twrip_upw.pval new file mode 100644 index 0000000000..9fd4ea76c0 --- /dev/null +++ b/examples/data/parameters/twrip_upw.pval @@ -0,0 +1,6 @@ +# Example pval +4 +HK1_z1 1.0E-3 +HK1_z2 1.0E-2 +VK1_z1 5.0E-4 +VK1_z2 5.0E-3 diff --git a/examples/data/parameters/twrip_upw.upw b/examples/data/parameters/twrip_upw.upw new file mode 100644 index 0000000000..bddc04f100 --- /dev/null +++ b/examples/data/parameters/twrip_upw.upw @@ -0,0 +1,35 @@ +# UPW Package input data for example problem +0 1.00E+30 10 0 IUPWCB HDRY NPUPW IPHDRY + 1 0 0 + 0 0 0 + 1. 1. 1. + 0 0 0 + 0 0 0 +HK1_z1 HK 1.0E-3 1 +1 NONE upwzones 1 +HK1_z2 HK 1.0E-3 1 +1 NONE upwzones 2 +HK2 HK 1.0E-4 1 +2 NONE ALL +HK3 HK 2.0E-4 1 +3 NONE ALL +VK1_z1 VK 1.0E-4 1 +1 NONE upwzones 1 +VK1_z2 VK 1.0E-4 1 +1 NONE upwzones 2 +VK2 VK 1.0E-5 1 +2 NONE ALL +VK3 VK 1.0E-5 1 +3 NONE ALL +VKCB1 VKCB 1.0 1 +1 MULT1 ALL +VKCB2 VKCB 0.5 1 +2 MULT1 ALL +0 HK layer 1 +0 VK layer 1 +0 VKCB layer 1 +0 HK layer 2 +0 VK layer 2 +0 VKCB layer 2 +0 HK ayer 3 +0 VK layer 3 diff --git a/examples/data/parameters/twrip_upw.zon b/examples/data/parameters/twrip_upw.zon new file mode 100644 index 0000000000..83b3328c7c --- /dev/null +++ b/examples/data/parameters/twrip_upw.zon @@ -0,0 +1,20 @@ +2 +RCHZONES +EXTERNAL 102 1 (free) 1 +upwzones +INTERNAL 1 (15I1) -1 +111111111111111 +111111111111111 +111111111111111 +111111111111111 +111111111111111 +111111111111111 +111111111111111 +111111111111111 +111111111111111 +111111111111111 +111111112211111 +111111122221111 +111111111222111 +111111111122222 +111111111111222 diff --git a/flopy/modflow/mfupw.py b/flopy/modflow/mfupw.py index 5635093113..6ac38005ed 100644 --- a/flopy/modflow/mfupw.py +++ b/flopy/modflow/mfupw.py @@ -408,7 +408,10 @@ def load(f, model, ext_unit_dict=None, check=True): ss = [0] * nlay sy = [0] * nlay vkcb = [0] * nlay + # load by layer for k in range(nlay): + + # hk if model.verbose: print(' loading hk layer {0:3d}...'.format(k + 1)) if 'hk' not in par_types: @@ -419,6 +422,8 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), 'hk', parm_dict, findlayer=k) hk[k] = t + + # hani if chani[k] < 1: if model.verbose: print(' loading hani layer {0:3d}...'.format(k + 1)) @@ -430,23 +435,26 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), 'hani', parm_dict, findlayer=k) hani[k] = t + + # vka if model.verbose: print(' loading vka layer {0:3d}...'.format(k + 1)) - if 'vk' not in par_types and 'vani' not in par_types: - key = 'vk' - if layvka[k] != 0: + key = 'vk' + if layvka[k] != 0: key = 'vani' + if 'vk' not in par_types and 'vani' not in par_types: t = Util2d.load(f, model, (nrow, ncol), np.float32, key, ext_unit_dict) else: line = f.readline() - key = 'vk' - if 'vani' in par_types: - key = 'vani' t = mfpar.parameter_fill(model, (nrow, ncol), key, parm_dict, findlayer=k) vka[k] = t + + # storage properties if transient: + + # ss if model.verbose: print(' loading ss layer {0:3d}...'.format(k + 1)) if 'ss' not in par_types: @@ -457,6 +465,8 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), 'ss', parm_dict, findlayer=k) ss[k] = t + + # sy if laytyp[k] != 0: if model.verbose: print(' loading sy layer {0:3d}...'.format(k + 1)) @@ -469,6 +479,8 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), 'sy', parm_dict, findlayer=k) sy[k] = t + + # vkcb if model.get_package('DIS').laycbd[k] > 0: if model.verbose: print(' loading vkcb layer {0:3d}...'.format(k + 1)) From e8106c8da600abdae8d08ae3cccb08c55aa8f5c3 Mon Sep 17 00:00:00 2001 From: ConstableCatnip <38230539+ConstableCatnip@users.noreply.github.com> Date: Tue, 10 Dec 2019 13:03:56 -0700 Subject: [PATCH 4/6] fix(upw): codacy errors fix(upw): codacy errors --- flopy/modflow/mfupw.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/flopy/modflow/mfupw.py b/flopy/modflow/mfupw.py index 6ac38005ed..f290b17bf1 100644 --- a/flopy/modflow/mfupw.py +++ b/flopy/modflow/mfupw.py @@ -251,11 +251,12 @@ def write_file(self, check=True, f=None): # Item 0: text f_upw.write('{}\n'.format(self.heading)) # Item 1: IBCFCB, HDRY, NPLPF - f_upw.write('{0:10d}{1:10.3G}{2:10d}{3:10d}{4:s}\n'.format(self.ipakcb, - self.hdry, - self.npupw, - self.iphdry, - self.options)) + f_upw.write('{0:10d}{1:10.3G}{2:10d}{3:10d}{4:s}\n' + .format(self.ipakcb, + self.hdry, + self.npupw, + self.iphdry, + self.options)) # LAYTYP array f_upw.write(self.laytyp.string) # LAYAVG array @@ -276,7 +277,7 @@ def write_file(self, check=True, f=None): if self.chani[k] < 1: f_upw.write(self.hani[k].get_file_entry()) f_upw.write(self.vka[k].get_file_entry()) - if transient == True: + if transient is True: f_upw.write(self.ss[k].get_file_entry()) if self.laytyp[k] != 0: f_upw.write(self.sy[k].get_file_entry()) @@ -390,7 +391,7 @@ def load(f, model, ext_unit_dict=None, check=True): laywet = read1d(f, laywet) # Item 7: WETFCT, IWETIT, IHDWET - wetfct, iwetit, ihdwet = None, None, None + iwetit = None iwetdry = laywet.sum() if iwetdry > 0: raise Exception('LAYWET should be 0 for UPW') @@ -410,7 +411,7 @@ def load(f, model, ext_unit_dict=None, check=True): vkcb = [0] * nlay # load by layer for k in range(nlay): - + # hk if model.verbose: print(' loading hk layer {0:3d}...'.format(k + 1)) @@ -422,7 +423,7 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), 'hk', parm_dict, findlayer=k) hk[k] = t - + # hani if chani[k] < 1: if model.verbose: @@ -435,13 +436,13 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), 'hani', parm_dict, findlayer=k) hani[k] = t - + # vka if model.verbose: print(' loading vka layer {0:3d}...'.format(k + 1)) key = 'vk' if layvka[k] != 0: - key = 'vani' + key = 'vani' if 'vk' not in par_types and 'vani' not in par_types: t = Util2d.load(f, model, (nrow, ncol), np.float32, key, ext_unit_dict) @@ -450,10 +451,10 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), key, parm_dict, findlayer=k) vka[k] = t - + # storage properties if transient: - + # ss if model.verbose: print(' loading ss layer {0:3d}...'.format(k + 1)) @@ -465,7 +466,7 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), 'ss', parm_dict, findlayer=k) ss[k] = t - + # sy if laytyp[k] != 0: if model.verbose: @@ -479,7 +480,7 @@ def load(f, model, ext_unit_dict=None, check=True): t = mfpar.parameter_fill(model, (nrow, ncol), 'sy', parm_dict, findlayer=k) sy[k] = t - + # vkcb if model.get_package('DIS').laycbd[k] > 0: if model.verbose: From 44696303fd69f2a096685aafc1ae900329c4cd9c Mon Sep 17 00:00:00 2001 From: ConstableCatnip <38230539+ConstableCatnip@users.noreply.github.com> Date: Tue, 10 Dec 2019 15:10:13 -0700 Subject: [PATCH 5/6] fix(upw): codacy errors Addressed codacy issues not associated with this pr. --- flopy/modflow/mfupw.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/flopy/modflow/mfupw.py b/flopy/modflow/mfupw.py index f290b17bf1..d11b5247a5 100644 --- a/flopy/modflow/mfupw.py +++ b/flopy/modflow/mfupw.py @@ -390,8 +390,7 @@ def load(f, model, ext_unit_dict=None, check=True): laywet = np.empty((nlay,), dtype=np.int32) laywet = read1d(f, laywet) - # Item 7: WETFCT, IWETIT, IHDWET - iwetit = None + # check that LAYWET is 0 for all layers iwetdry = laywet.sum() if iwetdry > 0: raise Exception('LAYWET should be 0 for UPW') From 9f30a834412883a2edcfd8ebf855b23536cc4948 Mon Sep 17 00:00:00 2001 From: ConstableCatnip <38230539+ConstableCatnip@users.noreply.github.com> Date: Thu, 12 Dec 2019 08:40:11 -0700 Subject: [PATCH 6/6] Remove 'is True' Remove 'is True' --- flopy/modflow/mfupw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flopy/modflow/mfupw.py b/flopy/modflow/mfupw.py index d11b5247a5..23f2446012 100644 --- a/flopy/modflow/mfupw.py +++ b/flopy/modflow/mfupw.py @@ -277,7 +277,7 @@ def write_file(self, check=True, f=None): if self.chani[k] < 1: f_upw.write(self.hani[k].get_file_entry()) f_upw.write(self.vka[k].get_file_entry()) - if transient is True: + if transient: f_upw.write(self.ss[k].get_file_entry()) if self.laytyp[k] != 0: f_upw.write(self.sy[k].get_file_entry())