From 37dc24a83256bed6a21013e6335874e44f6c5b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Mon, 14 Oct 2024 16:21:52 +0200 Subject: [PATCH 1/2] allow creating dataset from path to binary grid file (useful when reading in model results in separate scripts). --- nlmod/dims/grid.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 From 84d04db46462c9e7c054503e4487fa96d6946d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Mon, 14 Oct 2024 16:32:09 +0200 Subject: [PATCH 2/2] fix for reading heads using ds when no time has been set - default to float time index - fix for minor error introduced in #375 --- nlmod/mfoutput/mfoutput.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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