Skip to content

MeteoMapping.grid_mapping logic by xugrid CentroidLocatorRegridder #1162

Open
@Huite

Description

@Huite

This function:

def grid_mapping(svat: xr.DataArray, meteo_grid: xr.DataArray) -> pd.DataFrame:

contains logic to map the SVAT to the coarse meteo grid files. This logic is the same as the one that can be found in the xugrid CentroidLocatorRegridder:

https://deltares.github.io/xugrid/api/xugrid.CentroidLocatorRegridder.html

The latter one has the advantage of working on unstructured grids as well, and should have more unit tests and the like as well. I recommend replacing the grid_mapping logic by roughly the following:

regridder = xu.CentroidLocatorRegridder(source=svat, target=meteo_grid)
weights = regridder.weights_as_dataframe()
index = weights["target_index"]

Note that index is an a 1D array for indexing along the faces. You can generate 2D arrays relatively easily, using numpy unravel_index: https://numpy.org/doc/stable/reference/generated/numpy.unravel_index.html

row, column = np.unravel_index(index, shape=svat.shape)

Then, repeat for the number of subunits, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorRequires refactoring

    Type

    No type

    Projects

    Status

    📯 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions