Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeteoMapping.grid_mapping logic by xugrid CentroidLocatorRegridder #1162

Open
Huite opened this issue Aug 19, 2024 · 0 comments
Open

MeteoMapping.grid_mapping logic by xugrid CentroidLocatorRegridder #1162

Huite opened this issue Aug 19, 2024 · 0 comments

Comments

@Huite
Copy link
Contributor

Huite commented Aug 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📯 New
Development

No branches or pull requests

1 participant