Deltares / dfm_tools

A Python package for pre- and postprocessing D-Flow FM model input and output files
https://deltares.github.io/dfm_tools/
GNU General Public License v3.0
70 stars 11 forks source link

bounds attrs are not dropped for dropped variables #799

Open veenstrajelmer opened 8 months ago

veenstrajelmer commented 8 months ago

Bounds attrs are not dropped when linked variables are dropped upon merging. For instance, when merging the grevelingen mapfiles, the variables 'mesh2d_face_x_bnd' and 'mesh2d_face_y_bnd' since they cannot be aligned. However, the variables mesh2d_face_x and mesh2d_face_y have bounds attrs that are not dropped. When writing this to a file, we therefore end up with references to variables that are not available anymore.

MWE:

import dfm_tools as dfmt
uds = dfmt.data.fm_grevelingen_map()
print(uds.mesh2d_face_x.attrs)

Prints: {'units': 'm', 'standard_name': 'projection_x_coordinate', 'long_name': 'Characteristic x-coordinate of mesh face', 'mesh': 'mesh2d', 'location': 'face', 'bounds': 'mesh2d_face_x_bnd'}

mgeraeds commented 8 months ago

Adding on this, manually removing the bounds from the attributes does not seem to work; they will not be dropped, even with del uds['mesh2d_face_x'].attrs['bounds']. I only got it to work when first writing from an xu.UgridDataset to an xr.Dataset and then dropping the variables (through writing new attrs or using del on the 'bounds' attr).

veenstrajelmer commented 7 months ago

@mgeraeds you are referring to a quickplot crash when opening such a dataset. This happened only with a very old quickplot version (from 2018). With version 2.65.140745 (13-Feb-2022) and also higher versions, the missing bounds variables give a warning, but there is no crash and QuickPlot functions normally. It should still be solved eventually, but manually dropping the bounds attrs seems not necessary.