From 6c99092d5dd581a082814de81a984e211878c4cf Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Thu, 3 Oct 2019 15:34:46 -0700 Subject: [PATCH 1/2] Fix(SpatialReference): fix coordinate information being passed to SpatialReference class --- autotest/t007_test.py | 21 ++++++++++++++++++++- flopy/mbase.py | 8 ++++---- flopy/modflow/mfdis.py | 5 ++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/autotest/t007_test.py b/autotest/t007_test.py index 98327bfde..d901bf872 100644 --- a/autotest/t007_test.py +++ b/autotest/t007_test.py @@ -497,6 +497,24 @@ def test_free_format_flag(): assert ms1.free_format_input == ms1.bas6.ifrefm +def test_sr(): + import flopy + m = flopy.modflow.Modflow("test", model_ws="./temp", + xll=12345, yll=12345, + proj4_str="test test test") + flopy.modflow.ModflowDis(m,10,10,10) + m.sr.xll = 12345 + m.sr.yll = 12345 + m.write_input() + mm = flopy.modflow.Modflow.load("test.nam") + if mm.sr.xul != 12345: + raise AssertionError() + if mm.sr.yul != 12355: + raise AssertionError() + if mm.sr.proj4_str != "test test test": + raise AssertionError() + + def test_mg(): import flopy from flopy.utils import geometry @@ -1310,5 +1328,6 @@ def test_export_contourf(): # test_export_array() #test_export_array_contours() #test_tricontour_NaN() - test_export_contourf() + #test_export_contourf() + test_sr() pass diff --git a/flopy/mbase.py b/flopy/mbase.py index c6984e1ec..200cc549a 100644 --- a/flopy/mbase.py +++ b/flopy/mbase.py @@ -220,13 +220,13 @@ def __init__(self, modelname='modflowtest', namefile_ext='nam', warnings.warn('xul/yul have been deprecated. Use xll/yll instead.', DeprecationWarning) - rotation = kwargs.pop("rotation", 0.0) - proj4_str = kwargs.pop("proj4_str", None) + self._rotation = kwargs.pop("rotation", 0.0) + self._proj4_str = kwargs.pop("proj4_str", None) self._start_datetime = kwargs.pop("start_datetime", "1-1-1970") # build model discretization objects - self._modelgrid = Grid(proj4=proj4_str, xoff=xll, yoff=yll, - angrot=rotation) + self._modelgrid = Grid(proj4=self._proj4_str, xoff=xll, yoff=yll, + angrot=self._rotation) self._modeltime = None # Model file information diff --git a/flopy/modflow/mfdis.py b/flopy/modflow/mfdis.py index 4d852b731..e744b36f3 100644 --- a/flopy/modflow/mfdis.py +++ b/flopy/modflow/mfdis.py @@ -217,10 +217,13 @@ def __init__(self, model, nlay=1, nrow=2, ncol=2, nper=1, delr=1.0, yll = mg._yul_to_yll(yul) mg.set_coord_info(xoff=xll, yoff=yll, angrot=rotation, proj4=proj4_str) + xll = mg.xoffset + yll = mg.yoffset + rotation = mg.angrot with warnings.catch_warnings(): warnings.simplefilter("ignore", category=DeprecationWarning) self._sr = SpatialReference(self.delr, self.delc, self.lenuni, - xul=xul, yul=yul, + xll=xll, yll=yll, rotation=rotation or 0.0, proj4_str=proj4_str) From 1b66c3d55c6f7b023cc61bbdf34c6bb121933664 Mon Sep 17 00:00:00 2001 From: Joshua Larsen Date: Fri, 4 Oct 2019 12:42:03 -0700 Subject: [PATCH 2/2] update test_sr(), fixed path issue --- autotest/t007_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autotest/t007_test.py b/autotest/t007_test.py index d901bf872..9e6091624 100644 --- a/autotest/t007_test.py +++ b/autotest/t007_test.py @@ -506,7 +506,7 @@ def test_sr(): m.sr.xll = 12345 m.sr.yll = 12345 m.write_input() - mm = flopy.modflow.Modflow.load("test.nam") + mm = flopy.modflow.Modflow.load("test.nam", model_ws="./temp") if mm.sr.xul != 12345: raise AssertionError() if mm.sr.yul != 12355: