GenericMappingTools / GenericMappingTools/pygmt
Make a gmt xarray accessor to store metadata from grdinfo
- Dominant language
- Python
- Stars
- 874
- Forks
- 255
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 40
Description
**Description of the desired feature**
Metadata (data about data) is important, and there are specific kinds of metadata used by GMT when it decides how to plot a grid, such as:
- Registration type: Gridline/Pixel
- Coordinate system: Cartesian/Geographic
- Region: xmin/xmax, ymin/ymax, zmin/zmax
- Default Colormap (For GMT 6.1.0+ see https://github.com/GenericMappingTools/gmtserver-admin/pull/62)
Instead of explicitly wrapping `gmt info` or `gmt grdinfo` as in #147, why not allow the user to just **access** it via `grid.gmt.someattribute`? This would make use of [xarray accessors](http://xarray.pydata.org/en/v0.15.1/internals.html#extending-xarray) and call `grdinfo` under the hood to retrieve those metadata properties.
Pros:
- We can design it so that the attributes (e.g. z-range) update **dynamically** when we cut/transform/resample/etc the grid, unlike in https://github.com/pydata/xarray/issues/2247 where the attributes become out of date or are dropped with each operation
- Will be useful for autodetecting pixel/gridline registration in #476
- Won't need #494 so much anymore.
- Could store the region/projection information inside, and have `fig.basemap()` et al. use it automatically
- Tab-completion!!
- Avoids clashing with namespace of other libraries for things like `crs` and whatnot.
Cons:
- We would be designing yet another standard, as per https://xkcd.com/927/
- Would involve some development effort
- Might not be as discoverable as simply using `grid.attrs["someattribute"]` or `pygmt.grdinfo(grid)`, but that's just a documentation thing.
In reality, this `gmt` accessor can do more than just hold metadata. We could extend it to do `grid.gmt.plot` and more. But let's start with having it hold the metadata we want, and then build on top of it from there.
References:
- https://github.com/GenericMappingTools/pygmt/issues/147#issuecomment-450018956
- https://github.com/GenericMappingTools/pygmt/pull/476#discussion_r446874666
- https://github.com/pydata/xarray/issues/2247
Other xarray accessor examples:
- rioxarray - https://corteva.github.io/rioxarray/stable/examples/crs_management.html
- [cf-xarray](https://github.com/xarray-contrib/cf-xarray) (Get CF attributes)
- xgeo - https://geosynopsis.github.io/xgeo/docs/html/examples.html
- salem - https://salem.readthedocs.io/en/v0.2.3/xarray_acc.html
**Are you willing to help implement and maintain this feature?** Yes
Contributor guide
Assessment
This issue has not been assessed yet.