Deltares / xugrid

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

.ugrid.reindex_like rounding should happen before sorting, not just in coordinate check #196

Closed Huite closed 8 months ago

Huite commented 8 months ago

If a tolerance is specified, rounding should occur before sorting. Otherwise, it sorts by the x-axis first (e.g. on a difference of 1.0e-9), and then y, although these should be interpretered as representing the same value.

To get around this, we should express the coordinates in a discretized way, e.g. as integers:

    if tolerance > 0:
        to_sort_a = np.rint(xy_a / tolerance)
        to_sort_b = np.rint(xy_b / tolerance)
    else:
        to_sort_a = xy_a
        to_sort_b = xy_b

But a bit smarter.