Deltares / xugrid

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

"mode" method in regridder keeps repeating first value of source grid over target grid #236

Closed JoerivanEngelen closed 2 months ago

JoerivanEngelen commented 2 months ago

MWE, add to test_regridder.py:

def test_overlap_regridder_structured_values(grid_data_a):
    grid_data_adapted = grid_data_a.copy()
    grid_data_adapted.values[0, 0] = 99
    regridder = OverlapRegridder(source=grid_data_adapted, target=grid_data_a, method="mode")
    result = regridder.regrid(grid_data_adapted)
    assert not np.all(result == 99.0)

This test fails, instead all values are turned into the first value (99).

I've found the culprit: It has to do with an indexing bug in regrid.reduce.mode, working on a fix.