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
xu.open_dataset() adds several attrs to mesh2d that point to non-existing variables, like for instance 'boundary_node_connectivity': 'mesh2d_boundary_nodes'. This is an issue when using the file obtained from .ugrid.to_netcdf() in other processes.
MWE:
import xugrid as xu
import xarray as xr
file_nc = 'Grevelingen-FM_0000_map.nc'
file_nc = xu.data.adh_san_diego(xarray=True).encoding['source']
ds = xr.open_dataset(file_nc)
ds_mesh2d = ds.mesh2d.attrs
uds = xu.open_dataset(file_nc)
uds_mesh2d = uds.grid.to_dataset().mesh2d.attrs
uds_mesh2d_new = uds.grid.to_dataset().mesh2d.attrs
for key in ds_mesh2d.keys():
uds_mesh2d_new.pop(key)
print(uds_mesh2d_new)
for varn in uds_mesh2d_new.values():
try:
uds[varn]
except KeyError as e:
print(f'KeyError: {e}')
I've come across this issue myself as well: after writing the netCDF, QGIS via MDAL will not accept these attributes.
I think you can make two cases for how these attributes should be interpreted;
"This variable exists, under this name"
"If it exists, or if you create this variable, it will be under this name"
I went with the second interpretation -- though probably mostly due to implementation convenience since you can always assume the variables are all available. It allows for a relatively easy configuring of a naming scheme.
Regardless, if the unused variables are removed during the to_dataset() call, that behavior is maintained and other software shouldn't trip up.
xu.open_dataset()
adds several attrs tomesh2d
that point to non-existing variables, like for instance'boundary_node_connectivity': 'mesh2d_boundary_nodes'
. This is an issue when using the file obtained from.ugrid.to_netcdf()
in other processes.MWE:
Gives:
The text was updated successfully, but these errors were encountered: