diff --git a/flopy4/mf6/gwe/dis.py b/flopy4/mf6/gwe/dis.py index 030587d4..df91e2c7 100644 --- a/flopy4/mf6/gwe/dis.py +++ b/flopy4/mf6/gwe/dis.py @@ -126,6 +126,7 @@ def to_grid(self) -> StructuredGrid: @classmethod def from_grid(cls, grid: StructuredGrid) -> "Dis": + _lenunits = {1: "FEET", 2: "METERS", 3: "CENTIMETERS"} kwargs = { "xorigin": grid.xoffset, "yorigin": grid.yoffset, @@ -138,6 +139,10 @@ def from_grid(cls, grid: StructuredGrid) -> "Dis": "botm": grid.botm, "idomain": grid.idomain, } + if grid.lenuni in _lenunits: + kwargs["length_units"] = _lenunits[grid.lenuni] + if grid.angrot: + kwargs["angrot"] = grid.angrot if grid.crs is not None: kwargs["crs"] = f"EPSG:{grid.crs.to_epsg()}" return Dis(**kwargs) diff --git a/flopy4/mf6/gwf/dis.py b/flopy4/mf6/gwf/dis.py index f92311ba..10f40188 100644 --- a/flopy4/mf6/gwf/dis.py +++ b/flopy4/mf6/gwf/dis.py @@ -189,6 +189,7 @@ def from_grid(cls, grid: StructuredGrid) -> "Dis": Dis A discretization with the same dimensions and data as the grid. """ + _lenunits = {1: "FEET", 2: "METERS", 3: "CENTIMETERS"} kwargs = { "xorigin": grid.xoffset, "yorigin": grid.yoffset, @@ -201,6 +202,10 @@ def from_grid(cls, grid: StructuredGrid) -> "Dis": "botm": grid.botm, "idomain": grid.idomain, } + if grid.lenuni in _lenunits: + kwargs["length_units"] = _lenunits[grid.lenuni] + if grid.angrot: + kwargs["angrot"] = grid.angrot if grid.crs is not None: kwargs["crs"] = f"EPSG:{grid.crs.to_epsg()}" return Dis(**kwargs) diff --git a/flopy4/mf6/gwf/disv.py b/flopy4/mf6/gwf/disv.py index 8cadd94f..d7d2d709 100644 --- a/flopy4/mf6/gwf/disv.py +++ b/flopy4/mf6/gwf/disv.py @@ -204,22 +204,30 @@ def from_grid(cls, grid: VertexGrid) -> "Disv": Disv A discretization with the same dimensions and data as the grid. """ - return Disv( - xorigin=grid.xoffset, - yorigin=grid.yoffset, - nlay=grid.nlay, - ncpl=grid.ncpl, - nvert=grid.nvert, - top=grid.top, - botm=grid.botm, - idomain=np.asarray(grid.idomain).reshape(grid.nlay, grid.ncpl) + _lenunits = {1: "FEET", 2: "METERS", 3: "CENTIMETERS"} + kwargs = { + "xorigin": grid.xoffset, + "yorigin": grid.yoffset, + "nlay": grid.nlay, + "ncpl": grid.ncpl, + "nvert": grid.nvert, + "top": grid.top, + "botm": grid.botm, + "idomain": np.asarray(grid.idomain).reshape(grid.nlay, grid.ncpl) if grid.idomain is not None else None, - iv=np.array([v[0] for v in grid._vertices], dtype=int), - xv=grid.verts[:, 0].ravel(), - yv=grid.verts[:, 1].ravel(), - cell2ddata=Disv.grid_to_disv_cell2d(grid.cell2d), - ) + "iv": np.array([v[0] for v in grid._vertices], dtype=int), + "xv": grid.verts[:, 0].ravel(), + "yv": grid.verts[:, 1].ravel(), + "cell2ddata": Disv.grid_to_disv_cell2d(grid.cell2d), + } + if grid.lenuni in _lenunits: + kwargs["length_units"] = _lenunits[grid.lenuni] + if grid.angrot: + kwargs["angrot"] = grid.angrot + if grid.crs is not None: + kwargs["crs"] = f"EPSG:{grid.crs.to_epsg()}" + return Disv(**kwargs) @staticmethod def disv_to_grid_cell2d(cell2ddata) -> list: diff --git a/flopy4/mf6/gwt/dis.py b/flopy4/mf6/gwt/dis.py index 97350833..7d1f74fc 100644 --- a/flopy4/mf6/gwt/dis.py +++ b/flopy4/mf6/gwt/dis.py @@ -126,6 +126,7 @@ def to_grid(self) -> StructuredGrid: @classmethod def from_grid(cls, grid: StructuredGrid) -> "Dis": + _lenunits = {1: "FEET", 2: "METERS", 3: "CENTIMETERS"} kwargs = { "xorigin": grid.xoffset, "yorigin": grid.yoffset, @@ -138,6 +139,10 @@ def from_grid(cls, grid: StructuredGrid) -> "Dis": "botm": grid.botm, "idomain": grid.idomain, } + if grid.lenuni in _lenunits: + kwargs["length_units"] = _lenunits[grid.lenuni] + if grid.angrot: + kwargs["angrot"] = grid.angrot if grid.crs is not None: kwargs["crs"] = f"EPSG:{grid.crs.to_epsg()}" return Dis(**kwargs) diff --git a/flopy4/mf6/prt/dis.py b/flopy4/mf6/prt/dis.py index d7cf5ee5..c3b2fd62 100644 --- a/flopy4/mf6/prt/dis.py +++ b/flopy4/mf6/prt/dis.py @@ -114,6 +114,7 @@ def to_grid(self) -> StructuredGrid: @classmethod def from_grid(cls, grid: StructuredGrid) -> "Dis": + _lenunits = {1: "FEET", 2: "METERS", 3: "CENTIMETERS"} kwargs = { "xorigin": grid.xoffset, "yorigin": grid.yoffset, @@ -126,6 +127,10 @@ def from_grid(cls, grid: StructuredGrid) -> "Dis": "botm": grid.botm, "idomain": grid.idomain, } + if grid.lenuni in _lenunits: + kwargs["length_units"] = _lenunits[grid.lenuni] + if grid.angrot: + kwargs["angrot"] = grid.angrot if grid.crs is not None: kwargs["crs"] = f"EPSG:{grid.crs.to_epsg()}" return Dis(**kwargs)