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

Integration of pygmt with xarray and pyshtools #374

Open
MarkWieczorek opened this issue Nov 8, 2019 · 1 comment
Open

Integration of pygmt with xarray and pyshtools #374

MarkWieczorek opened this issue Nov 8, 2019 · 1 comment
Labels
feature request New feature wanted

Comments

@MarkWieczorek
Copy link
Contributor

MarkWieczorek commented Nov 8, 2019

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 SHTOOLS/SHTOOLS#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:

  • projection: The name of a global or hemispherical projection (see Notes). Only the first three characters are necessary to identify the projection.
  • region: The map region, consisting of a list [West, East, South, North] in degrees. The default 'g' specifies the entire sphere.
  • width: The wdith of the projected image.
  • unit: The measurement unit of the figure width and shift_origin: 'i' for inches or 'c' for cm.
  • longitude: The central meridian or center of the projection.
  • latitude: The center of the projection for some hemispheric projections.
  • grid: If True, plot grid lines.
  • grid_interval: Grid line interval [latitude, longitude] in degrees.
  • annotate: If True, plot annotation labels on axes.
  • annotate_interval: Annotation label interval [latitude, longitude] in degrees.
  • ticks: If True, plot ticks on axes.
  • tick_interval: Tick interval [latitude, longitude] in degrees.
  • axes: Specify which plot axes should be drawn and annotated. Capital letters draw the axes, ticks, and annotations, whereas small letters draw only the axes and ticks.
  • title: The title to be displayed above the plot.
  • cmap : The color map to use when plotting the data and colorbar.
  • cmap_reverse: Set to True to reverse the sense of the color progression in the color table.
  • continuous: If True, create a continuous colormap. Default behavior is to use contant colors for each interval.
  • limits: A list containing the lower and upper limits of the data to be used with the color map, and optionally an interval.
  • colorbar: If True, plot a colorbar.
  • cb_orientation: Orientation of the colorbar; either 'h' or 'v' for horizontal or vertical, respectively.
  • cb_triangles: Add triangles to the edges of the colorbar for background 'b' and/or foreground 'f' colors.
  • cb_label: Text label for the colorbar.
  • cb_ylabel: Text label for the y axis of the colorbar
  • cb_annotate: If True, plot annotation labels on the colorbar.
  • cb_annotate_interval: Annotation interval on the colorbar.
  • cb_ticks: If True, plot ticks on the colorbar.
  • cb_tick_interval: Colorbar tick interval.
  • shift_origin: Offset of the plot in the x and y directions from the origin.
  • fname: If present, save the image to the specified file.
@weiji14
Copy link
Member

weiji14 commented Nov 8, 2019

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. #329 (comment)), but there's a work-in-progress PR upstream at GenericMappingTools/gmt#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) 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature wanted
Projects
None yet
Development

No branches or pull requests

2 participants