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
Unfortunately, dflowfm does not read the start_index attribute but assumes 1. When writing a newly generated meshkernelpy grid (start_index=0, _FillValue=-1) to a netcdf file, the start_index has to be converted to 1. Currently, dfm_tools uses this workaround in meshkernel_to_UgridDataset():
mesh2d_grid=mk.mesh2d_get()
xu_grid=xu.Ugrid2d.from_meshkernel(mesh2d_grid)
#convert 0-based to 1-based indices for connectivity variables like face_node_connectivityxu_grid_ds=xu_grid.to_dataset()
xu_grid_ds=xr.decode_cf(xu_grid_ds) #decode_cf is essential since it replaces fillvalues with nansds_idx=xu_grid_ds.filter_by_attrs(start_index=0)
forvarn_conninds_idx.data_vars:
xu_grid_ds[varn_conn] +=1#from startindex 0 to 1 (fillvalues are now nans, so this is safe to do)xu_grid_ds[varn_conn].attrs["start_index"] +=1xu_grid_ds[varn_conn].encoding["_FillValue"] =-1#can be any value <=0, but non-zero is currently the most convenient for proper xugrid plots of node variables.# convert to uds and add attrs and crsxu_grid_uds=xu.UgridDataset(xu_grid_ds)
I can imagine that 1-based face_node_connectivity causes issues in 0-based Python. Could we maybe simplify the above process by for instance not changing the internal data, but instead upon writing a netcdf file with uds.ugrid.to_netcdf(), providing an argument start_index=1? Any other alternative is also fine.
The text was updated successfully, but these errors were encountered:
veenstrajelmer
changed the title
support writing of netfile with start_index=1 and _FillValue=0
support writing of netfile with start_index=1 and _FillValue!=-1Jul 12, 2023
Unfortunately, dflowfm does not read the
start_index
attribute but assumes 1. When writing a newly generated meshkernelpy grid (start_index=0
,_FillValue=-1
) to a netcdf file, thestart_index
has to be converted to 1. Currently, dfm_tools uses this workaround in meshkernel_to_UgridDataset():I can imagine that 1-based
face_node_connectivity
causes issues in 0-based Python. Could we maybe simplify the above process by for instance not changing the internal data, but instead upon writing a netcdf file withuds.ugrid.to_netcdf()
, providing an argumentstart_index=1
? Any other alternative is also fine.The text was updated successfully, but these errors were encountered: