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
When writing+reading a subset of a dataset, the get_Dataset_atdepths plots an unexpected empty (all-nan) field. This happens because variables that are missing a _FillValue attribute in the encoding are set to _FillValue=nan upon xarray's .to_dataset(). The default fillvalue parsing that normally happens in get_Dataset_atdepths then does not work anymore.
MWE:
importdfm_toolsasdfmtimportxugridasxuimportmatplotlib.pyplotaspltplt.close("all")
file_nc=r'p:\11209731-002-nutrient-reduction-ta\runs_OSPAR\B05_waq_withDOM_2015\DFM_OUTPUT_DCSM-FM_0_5nm_waq\DCSM-FM_0_5nm_waq_0000_map.nc'uds=xu.open_dataset(file_nc)
uds_sel=uds[['mesh2d_ucx', 'mesh2d_ucy',
"mesh2d_s1", "mesh2d_bldepth", "mesh2d_sigmazdepth", "mesh2d_interface_z", "mesh2d_interface_sigma",
'mesh2d_layer_sigma', 'mesh2d_layer_z', "mesh2d_layer_sigma_z", "mesh2d_interface_sigma_z",
'mesh2d_flowelem_bl']]
write_read=Trueifwrite_read:
file_temp="test_sonia.nc"uds_sel.ugrid.to_netcdf(file_temp)
# Re-reading subsetted fileuds_sel_fromfile=dfmt.open_partitioned_dataset(file_temp)
print("read_write finished")
else:
uds_sel_fromfile=uds_selprint("print fillvalues in original dataset")
ds=uds_selforvarninds.obj.variables:
if'_FillValue'inds[varn].encoding:
print(varn, ds[varn].encoding['_FillValue'])
print()
print("print fillvalues in write+read dataset")
ds=uds_sel_fromfileforvarninds.obj.variables:
if'_FillValue'inds[varn].encoding:
print(varn, ds[varn].encoding['_FillValue'])
# depth extractionuds_crop_sel_atdepth=dfmt.get_Dataset_atdepths(uds_sel, depths=0, reference='bedlevel')
uds_crop_sel_atdepth_fromfile=dfmt.get_Dataset_atdepths(uds_sel_fromfile, depths=0, reference='bedlevel')
# plottingfig, ax=plt.subplots()
uds_crop_sel_atdepth.mesh2d_ucx.isel(time=0).ugrid.plot(cmap='jet')
fig, ax=plt.subplots()
uds_crop_sel_atdepth_fromfile.mesh2d_ucx.isel(time=0).ugrid.plot(cmap='jet') # blank plot in this case (only nans in this partition)
Expected (result without write+read):
Actual (with write+read):
The text was updated successfully, but these errors were encountered:
In the linked PR there is a workaround implemented in dfmt.open_partitioned_dataset that pops the _FillValue attrs that are nan. However, it is still inconvenient behaviour by xarray and would be good if solved in the future. Therefore we added test_remove_nan_fillvalue_attrs, to keep track if xarray fixes this themselves. Follow-up issue in Deltares/xugrid#176
When writing+reading a subset of a dataset, the
get_Dataset_atdepths
plots an unexpected empty (all-nan) field. This happens because variables that are missing a _FillValue attribute in the encoding are set to _FillValue=nan upon xarray's.to_dataset()
. The default fillvalue parsing that normally happens inget_Dataset_atdepths
then does not work anymore.MWE:
Expected (result without write+read):

Actual (with write+read):

The text was updated successfully, but these errors were encountered: