From 471124b42fb98a66d09a98fdb08c90a8bb101587 Mon Sep 17 00:00:00 2001 From: White Date: Thu, 5 Sep 2019 15:03:19 -0500 Subject: [PATCH 1/5] added grid interect to util init --- flopy/utils/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flopy/utils/__init__.py b/flopy/utils/__init__.py index a4da708b9c..2dfdd58352 100644 --- a/flopy/utils/__init__.py +++ b/flopy/utils/__init__.py @@ -45,3 +45,4 @@ from .mtlistfile import MtListBudget from .optionblock import OptionBlock from .rasters import Raster +from .gridintersect import GridIntersect,ModflowGridIndices \ No newline at end of file From 4deb1cde8270fcc43fd8b90c0d51d74f1858f5ef Mon Sep 17 00:00:00 2001 From: White Date: Thu, 19 Sep 2019 13:57:13 -0500 Subject: [PATCH 2/5] fix(binaryfile): CellBudgetFile.get_ts() wasnt setting times correctly if no times were passed but model instance is available --- flopy/utils/binaryfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flopy/utils/binaryfile.py b/flopy/utils/binaryfile.py index b361425008..0df4dbc36b 100755 --- a/flopy/utils/binaryfile.py +++ b/flopy/utils/binaryfile.py @@ -1193,8 +1193,8 @@ def get_ts(self, idx, text=None, times=None): 'not {}'.format(len(times)) raise Exception(etxt) timesint = times - for idx, t in enumerate(timesint): - result[idx, 0] = t + for idx, t in enumerate(timesint): + result[idx, 0] = t for itim, k in enumerate(kk): v = self.get_data(kstpkper=k, text=text, full3D=True) From 05c8f33b10afa9d2e6ec81546c37206ca5346005 Mon Sep 17 00:00:00 2001 From: White Date: Wed, 6 Nov 2019 17:03:21 -0700 Subject: [PATCH 3/5] fix(irch): subtract one from irch at load, add one to irch at write --- autotest/t020_test.py | 38 +++++++++++++++++++++++++++++++++++++- flopy/modflow/mfrch.py | 14 +++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/autotest/t020_test.py b/autotest/t020_test.py index fd10159d6a..2d4d754751 100644 --- a/autotest/t020_test.py +++ b/autotest/t020_test.py @@ -147,5 +147,41 @@ def test_mfnwt_run(): return +def test_irch(): + import os + import flopy + org_model_ws = os.path.join("..","examples","data","freyberg_multilayer_transient") + nam_file = "freyberg.nam" + m = flopy.modflow.Modflow.load(nam_file,model_ws=org_model_ws,check=False,forgive=False, + verbose=True) + irch = {} + for kper in range(m.nper): + arr = np.random.randint(0,m.nlay,size=(m.nrow,m.ncol)) + irch[kper] = arr + + m.remove_package("RCH") + flopy.modflow.ModflowRch(m,rech=0.1,irch=irch,nrchop=2) + + for kper in range(m.nper): + arr = irch[kper] + aarr = m.rch.irch[kper].array + d = arr - aarr + assert np.abs(d).sum() == 0 + + + new_model_ws = "temp" + m.change_model_ws(new_model_ws) + m.write_input() + mm = flopy.modflow.Modflow.load(nam_file,model_ws="temp",forgive=False,verbose=True, + check=False) + for kper in range(m.nper): + arr = irch[kper] + aarr = mm.rch.irch[kper].array + d = arr - aarr + assert np.abs(d).sum() == 0 + + + if __name__ == '__main__': - test_mfnwt_run() + # test_mfnwt_run() + test_irch() diff --git a/flopy/modflow/mfrch.py b/flopy/modflow/mfrch.py index e0d6b47463..60ae793633 100644 --- a/flopy/modflow/mfrch.py +++ b/flopy/modflow/mfrch.py @@ -141,7 +141,7 @@ def __init__(self, model, nrchop=3, ipakcb=None, rech=1e-3, irch=0, rech, name='rech_') if self.nrchop == 2: self.irch = Transient2d(model, (nrow, ncol), np.int32, - irch + 1, + irch, name='irch_') else: self.irch = None @@ -287,10 +287,17 @@ def write_file(self, check=True, f=None): f_rch = open(self.fn_path, 'w') f_rch.write('{0:s}\n'.format(self.heading)) f_rch.write('{0:10d}{1:10d}\n'.format(self.nrchop, self.ipakcb)) + + if self.nrchop == 2: + irch = {} + for kper,u2d in self.irch.transient_2ds.items(): + irch[kper] = u2d.array + 1 + irch = Transient2d(self.parent,self.irch.shape,self.irch.dtype,irch,self.irch.name) + for kper in range(nper): inrech, file_entry_rech = self.rech.get_kper_entry(kper) if self.nrchop == 2: - inirch, file_entry_irch = self.irch.get_kper_entry(kper) + inirch, file_entry_irch = irch.get_kper_entry(kper) else: inirch = -1 f_rch.write('{0:10d}{1:10d} # {2:s}\n'.format(inrech, @@ -426,7 +433,8 @@ def load(f, model, nper=None, ext_unit_dict=None, check=True): print(txt) t = Util2d.load(f, model, (nrow, ncol), np.int32, 'irch', ext_unit_dict) - current_irch = t + current_irch = Util2d(model,(nrow, ncol), np.int32, + t.array - 1, "irch") irch[iper] = current_irch if openfile: From 2c3e6588b45bf981bfb69115caa4a978f7814e64 Mon Sep 17 00:00:00 2001 From: White Date: Thu, 7 Nov 2019 08:17:30 -0700 Subject: [PATCH 4/5] codacy bs --- flopy/modflow/mfrch.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flopy/modflow/mfrch.py b/flopy/modflow/mfrch.py index 60ae793633..d82e3fe6a3 100644 --- a/flopy/modflow/mfrch.py +++ b/flopy/modflow/mfrch.py @@ -292,7 +292,11 @@ def write_file(self, check=True, f=None): irch = {} for kper,u2d in self.irch.transient_2ds.items(): irch[kper] = u2d.array + 1 - irch = Transient2d(self.parent,self.irch.shape,self.irch.dtype,irch,self.irch.name) + irch = Transient2d(self.parent + ,self.irch.shape, + self.irch.dtype, + irch, + self.irch.name) for kper in range(nper): inrech, file_entry_rech = self.rech.get_kper_entry(kper) From 763d10788d3c0c7a44f6904b3135258ff35eaedc Mon Sep 17 00:00:00 2001 From: White Date: Thu, 7 Nov 2019 12:25:21 -0700 Subject: [PATCH 5/5] added trap on t032 for CRS.getprj() returns None --- autotest/t007_test.py | 4 ++-- autotest/t032_test.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/autotest/t007_test.py b/autotest/t007_test.py index 9f83fb6edf..9d8fdc8de6 100644 --- a/autotest/t007_test.py +++ b/autotest/t007_test.py @@ -1312,7 +1312,7 @@ def test_export_contourf(): # test_vertex_model_dot_plot() #test_sr_with_Map() #test_modelgrid_with_PlotMapView() - # test_epsgs() + test_epsgs() # test_sr_scaling() # test_read_usgs_model_reference() #test_dynamic_xll_yll() @@ -1330,5 +1330,5 @@ def test_export_contourf(): #test_export_array_contours() #test_tricontour_NaN() #test_export_contourf() - test_sr() + #test_sr() pass diff --git a/autotest/t032_test.py b/autotest/t032_test.py index 0b30b24f1b..c1e2b16fb0 100644 --- a/autotest/t032_test.py +++ b/autotest/t032_test.py @@ -82,10 +82,13 @@ def test_epsgreference(): ep.reset() ep.show() - prjtxt = CRS.getprj(32614) # WGS 84 / UTM zone 14N + prjtxt = CRS.getprj(32614) # WGS 84 / UTM zone 14N + if prjtxt is None: + print("unable to retrieve CRS prj txt") + return if sys.version_info[0] == 2: prjtxt = prjtxt.encode('ascii') - assert isinstance(prjtxt, str) + assert isinstance(prjtxt, str),type(prjtxt) prj = ep.to_dict() assert 32614 in prj ep.show() @@ -111,5 +114,5 @@ def test_epsgreference(): if __name__ == '__main__': #test_polygon_from_ij() - #test_epsgref() + test_epsgreference() pass