diff --git a/nlmod/dims/grid.py b/nlmod/dims/grid.py index de2fd6aa..4a258040 100644 --- a/nlmod/dims/grid.py +++ b/nlmod/dims/grid.py @@ -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 diff --git a/nlmod/mfoutput/mfoutput.py b/nlmod/mfoutput/mfoutput.py index 0e98c874..906f9d34 100644 --- a/nlmod/mfoutput/mfoutput.py +++ b/nlmod/mfoutput/mfoutput.py @@ -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