Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:gwmod/nlmod into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
OnnoEbbens committed Oct 15, 2024
2 parents bc0d600 + 84d04db commit 7f6a79e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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
8 changes: 7 additions & 1 deletion nlmod/mfoutput/mfoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ def _get_time_index(fobj, ds=None, gwf_or_gwt=None):
time_units=gwf_or_gwt.modeltime.time_units,
)
elif ds is not None:
if "time" in ds:
dtype = "float" if ds.time.dtype.kind in ["i", "f"] else "datetime"
else:
dtype = "float"
tindex = ds_time_idx(
fobj.get_times(),
start_datetime=(ds.time.attrs["start"] if "time" in ds else None),
time_units=(ds.time.attrs["time_units"] if "time" in ds else None),
dtype="float" if ds.time.dtype.kind in ["i", "f"] else "datetime",
dtype=dtype,
)
else:
raise ValueError("Provide either ds or gwf_or_gwt")
return tindex


Expand Down

0 comments on commit 7f6a79e

Please sign in to comment.