GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
758 stars 220 forks source link

Integration of pygmt with xarray and pyshtools #374

Open MarkWieczorek opened 5 years ago

MarkWieczorek commented 5 years ago

Plotting of projected images using xarray and/or pyshtools

It would be desirable to add a method such as plot_gmt() or gmt.plot() to xarray DataArrays and pyshtools SHGrids (the latter of which are easily converted to DataArrays). Through a single command, it would thus be possible to create a publication quality projected image. Such a built in method would have a set of default plotting parameters defined, and would require only minimal modifications on the part of the user.

pyshtools implementation

I have just made a pull request at pyshtools https://github.com/SHTOOLS/SHTOOLS/pull/203 which is a first attempt of plotting global grids. This method implements all global and hemispherical projects, and latter will be updated to work with non-global projections. By simply calling plot_gmt() a global mollweide projected image is created.

This method defines a large number of human-readable parameters that differ from the standard gmt syntax (which is only understandable by an expert), but also differs in places by what pygmt uses. Ideally, it would be useful if we could try to standardize the syntax among the various gmt-related projects. Here is what I am currently using, but I could be easily convinced to change these:

weiji14 commented 5 years ago

This is a wonderful idea! There is this concept of an xarray accessor of which salem's implementation is a good example (using a matplotlib backend with cartopy as projection lib) you might want to take a look at. If I'm reading this right, we could essentially have a 'gmt' backend as well. The way it would work is something like

xr.DataArray.gmt.plot()

This also draws parallels with hvplot (see Geographic Example) that has a similar 'data' first, then 'plot' syntax, in contrast to the 'plot' first, then 'data' syntax which pygmt and matplotlib uses.

For the standardized syntax request (or aliases as we usually refer to it here), that's something I've bumped into a lot, and requires coordination with the Julia and Matlab wrappers as well. I would suggest posting on our new forum where you'll get more visibility from the others. At the moment it's done on an ad-hoc basis (e.g. https://github.com/GenericMappingTools/pygmt/pull/329#issuecomment-536178749), but there's a work-in-progress PR upstream at https://github.com/GenericMappingTools/gmt/pull/230 that will handle part of this.

I've had a look at your plot_gmt code and this chunk of projection name parsing is essentially what we want to achieve in #356. How about we start with that part? That just means you won't have to maintain it in SHTOOLS and we get nice projection handling in pygmt (win win) :smile: