Deltares / xugrid

Xarray and unstructured grids
https://deltares.github.io/xugrid/
MIT License
61 stars 8 forks source link

`uds.ugrid.sel_points()` also broadcasts face_dimension on variables without it #274

Open veenstrajelmer opened 1 month ago

veenstrajelmer commented 1 month ago

The code below adds a face_dimension to variables that not defined there if some of the points are out of bounds.


import numpy as np
import xugrid as xu
import xarray as xr

uds = xu.data.adh_san_diego()
facedim = uds.grid.face_dimension
facesize = uds.grid.sizes[facedim]
uds['face_var'] = xr.DataArray(np.ones((facesize)), dims=facedim)
ds = uds.ugrid.sel_points(x=[475153,475153,1],y=[3621027,3621027,1])

print(uds.elevation.dims)
print(ds.elevation.dims)

Prints:

('node',)
('node', 'face')

If only providing points that are in bounds, this issue does not occur and ds.elevation has only a node dimension.

Huite commented 1 month ago

This is due to the fact that isel doesn't broadcast, but .where does.

Might have to solve it by filtering variables based on dimension, then only applying where if the dimension is present.