Open
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 Add a CPT column to the gmt_data_server.txt file gmtserver-admin#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 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 Indexing preserves outdated attrs which cause trouble downstream pydata/xarray#2247 where the attributes become out of date or are dropped with each operation
- Will be useful for autodetecting pixel/gridline registration in Properly allow for either pixel or gridline registered grids #476
- Won't need More informative metadata when loading earth_relief grids #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"]
orpygmt.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:
- Return values of gmt.info #147 (comment)
- Properly allow for either pixel or gridline registered grids #476 (comment)
- Indexing preserves outdated attrs which cause trouble downstream pydata/xarray#2247
Other xarray accessor examples:
- rioxarray - https://corteva.github.io/rioxarray/stable/examples/crs_management.html
- 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