Skip to content

Commit

Permalink
208 gridrefine raises incomprehensible valueerror when there is a dat…
Browse files Browse the repository at this point in the history
…a variable with dtype object present in the dataset (#209)

* fix for #208

* better log message
  • Loading branch information
OnnoEbbens authored Jul 20, 2023
1 parent a49d63c commit 827495c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nlmod/dims/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@ def ds_to_gridprops(ds_in, gridprops, method="nearest", nodata=-1):
xyi, _ = get_xyi_icell2d(gridprops)
x = xr.DataArray(xyi[:, 0], dims=("icell2d",))
y = xr.DataArray(xyi[:, 1], dims=("icell2d",))

# drop non-numeric data variables
for key, dtype in ds_in.dtypes.items():
if not np.issubdtype(dtype, np.number):
ds_in = ds_in.drop_vars(key)
logger.info(
f"cannot convert data variable {key} to refined dataset because of non-numeric dtype"
)

if method in ["nearest", "linear"]:
# resample the entire dataset in one line
ds_out = ds_in.interp(x=x, y=y, method=method, kwargs={"fill_value": None})
Expand Down

0 comments on commit 827495c

Please sign in to comment.