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 13 forks source link

rasterize_ugrid #1020

Closed francescamessina closed 1 month ago

francescamessina commented 1 month ago

I am trying to use rasterize_ugrid on a variable defined at the mesh2d_nEdges (specifically variable "mesh2d_vicwwu"). But I am getting this error:

_ValueError: Dimensions {'mesh2d_nFaces'} do not exist. Expected one or more of FrozenMappingWarningOnValuesAccess({'mesh2dnEdges': 14302, 'time': 1457})" }

Is rasterize_ugrid meant to work only with variables defined at the mesh2d_nFaces?

I am following the approach explained here: https://github.com/Deltares/dfm_tools/blob/main/tests/examples/postprocess_mapfile_to_regulargrid.py

Thanks

veenstrajelmer commented 1 month ago

Hi @francescamessina. dfm_tools uses xugrid for rasterization (and many other things), the docs for this specific function are here: https://deltares.github.io/xugrid/api/xugrid.Ugrid2d.rasterize_like.html In this function xugrid samples data, so it has to come from some filled variable. However, dfm_tools has the function dfmt.uda_to_faces() with which you can interpolate the edge variables to faces. If this is not what you are looking for, you might also want to consider regridding: https://deltares.github.io/xugrid/examples/regridder_overview.html Hope this helps. I will close this issues since no dfm_tools code updates are required, but feel free to reply to it anyway.

francescamessina commented 1 month ago

@veenstrajelmer thank you so much for your response. My goal is to interpolate the Delft3D FM model output to a regular grid. I did it successfully for the variables defined at the faces (using rasterize_ugrid), but I am getting an error for the variables defined on the edges. I will try to interpolate them first to the faces using dfmt.uda_to_faces() and then to a regular grid. Thanks

francescamessina commented 1 month ago

Worked great! Thanks again