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

Implement cell bounds convention for xarray #177

Open
Manangka opened this issue May 18, 2021 · 1 comment
Open

Implement cell bounds convention for xarray #177

Manangka opened this issue May 18, 2021 · 1 comment

Comments

@Manangka
Copy link
Collaborator

In GitLab by @Huite on May 18, 2021, 14:34

It looks like xarray finally has some support for cell boundaries arrays: pydata/xarray#2844

The default option is simply storing cell "midpoints", but this is strictly insufficient to derive the boundaries, if cell size is not a constant (like it is in general GIS rasters).

MODFLOW supports non-equidistant grids, and thus IDFs (and of course netCDFs) can be non-equidistant. To support regridding in these cases, I had to invent my own convention of storing d coordinates for the cell sizes (dz, dy, dx). Unfortunately, while there is some precedent for scalar cell sizes (e.g. from xr.open_rasterio), this is not the case for array cell sizes.

So rather than storing dy and dx arrays for non-equidistant data, we could simply store the cell boundaries instead. Note that cell centers are still required as a coordinate, since software like GDAL or MDAL will not look at boundaries at all. In some cases, dx and dy are useful (e.g. to compute cell area), but having an ad hoc / informal convention like this is a big downside.

I guess we could slowly deprecate dx and dy (and dz) coordinate arrays?

This has no relation with either MDAL or GDAL: currently they do not understand either. Given the fact, however, that cell bounds is CF compliant, while dx and dy coordinates are not, makes it a lot more likely for bounds support to be included at some point in the future.

Some changes:

  • Convert IDF dx and dy arrays to cell bounds
  • Maintain scalar dx and dy, since xr.open_rasterio still does this (also means that most use will not be impacted, since non-equidistant grids are quite rare)
  • Deprecate (in due time) the dx and dy array based logic. This removes the duck typing complexities for dx and dy, since they can always be assumed to be scalar.
  • For the regridder, it no longer needs to infer cell boundaries, they are assumed given. For scalar dx, they are (still) easily computed. Will still need an equidistance check (but checks for presence of cell boundaries, rather than presence of dx dy coords).
  • For IDF output: automatically convert cell boundary coordinates to the required dx and dy arrays in case of non-equidistance.
@Manangka
Copy link
Collaborator Author

In GitLab by @Huite on Nov 14, 2022, 17:27

Note, while this works for datasets, it (still) doesn't work for DataArrays: pydata/xarray#1475

@JoerivanEngelen JoerivanEngelen removed the legacy_regridder Uses iMOD Python's legacy regridder (instead of xugrid's regridder) label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants