You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This raises "ValueError: connectivity contains negative values":
import xugrid as xu
file_nc = r'p:\archivedprojects\1210301-dflow-fm\MeinardTiessen\model\NEVLA\a19\DFM_OUTPUT_WS13_new_04\WS13_new_04_0000_map.nc'
ds = xu.open_dataset(file_nc)
For now, a workaround is to add the default fillvalue to the attributes before feeding to xugrid:
import xugrid as xu
import xarray as xr
file_nc = r'p:\archivedprojects\1210301-dflow-fm\MeinardTiessen\model\NEVLA\a19\DFM_OUTPUT_WS13_new_04\WS13_new_04_0000_map.nc'
ds = xr.open_dataset(file_nc)
#add default fillvalue if missing from connectivity array attrs
varn_conn = 'NetElemNode'
if ds[varn_conn].min()<0 and '_FillValue' not in ds[varn_conn].attrs:
from netCDF4 import default_fillvals
dtype_str = ds[varn_conn].dtype.str[1:]
ds[varn_conn] = ds[varn_conn].assign_attrs({'_FillValue':default_fillvals[dtype_str]})
#decode_cf again, fillvalues are replaced with nan and _FillValue attr is moved to encoding
ds = xr.decode_cf(ds)
uds = xu.core.wrap.UgridDataset(ds)
We will probably wait on xarray to fix their issue. If it takes too long, we might want to implement a workaround.
This will not be added in xugrid. It is temporarily added in dfm_tools in Deltares/dfm_tools#496 and it will be removed again once xarray handles default fillvalues.
xarray does not use the default netcdf4 fillvalue in
decode_cf
, only the explicitly set_FillValue
attribute: pydata/xarray#7723 and pydata/xarray#2374 and pydata/xarray#2742This raises
"ValueError: connectivity contains negative values"
:For now, a workaround is to add the default fillvalue to the attributes before feeding to xugrid:
We will probably wait on xarray to fix their issue. If it takes too long, we might want to implement a workaround.
This is also an issue for non-connectivity variables: Deltares/dfm_tools#490
The text was updated successfully, but these errors were encountered: