Skip to content

Commit

Permalink
allow creating dataset from path to binary grid file
Browse files Browse the repository at this point in the history
(useful when reading in model results in separate scripts).
  • Loading branch information
dbrakenhoff committed Oct 14, 2024
1 parent d7b6bb8 commit 37dc24a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nlmod/dims/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,25 @@ def modelgrid_to_vertex_ds(mg, ds, nodata=-1):
return ds


def modelgrid_to_ds(mg):
def modelgrid_to_ds(mg=None, grbfile=None):
"""Create Dataset from flopy modelgrid object.
Parameters
----------
mg : flopy.discretization.Grid
flopy modelgrid object
grbfile : str
path to a binary grid file
Returns
-------
ds : xarray.Dataset
Dataset containing grid information
"""
if mg is None and grbfile is not None:
mg = flopy.utils.MfGrdFile(grbfile).modelgrid
elif mg is None and grbfile is None:
raise ValueError("Either 'mg' or 'grbfile' should be specified!")
if mg.grid_type == "structured":
x, y = mg.xyedges
from .base import _get_structured_grid_ds
Expand Down

0 comments on commit 37dc24a

Please sign in to comment.