Deltares / imod-python

🐍🧰 Make massive MODFLOW models
https://deltares.github.io/imod-python/
MIT License
18 stars 3 forks source link

Implement cell bounds convention for xarray #177

Open Manangka opened 3 years ago

Manangka commented 3 years ago

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

It looks like xarray finally has some support for cell boundaries arrays: https://github.com/pydata/xarray/pull/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:

Manangka commented 1 year ago

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

Note, while this works for datasets, it (still) doesn't work for DataArrays: https://github.com/pydata/xarray/issues/1475