GenericMappingTools/pygmt

problems with grdcontour when using xarray DataArrays

Opened this issue · 0 comments

Description of the problem

I am attempting to draw a contour which encompasses the south pole using grdcontour. Everything works fine when passing a netcdf filename, but when passing an xarray DataArray, the points at the far left and right of the plot are connected by a straight line.

Here is the image using a DataArray
grid1

And here is the image using the netcdf file
grid2

I note that the second image generates a warning (as shown below), but it works nonetheless.

Minimal Complete Verifiable Example

# create a dummy dataset
interval = 0.2
lat = np.arange(90, -90 - interval, -interval)
lon = np.arange(0, 360 + interval, interval)
longrid, latgrid = np.meshgrid(lon, lat)
data = 0.2 * np.cos(np.deg2rad(longrid)) + np.sin(np.deg2rad(latgrid))
grid = xr.DataArray(data, coords=[("latitude", lat), ("longitude", lon)])
grid.gmt.registration = 0
grid.gmt.gtype = 1
grid.to_netcdf('grid.nc')

# plot and use grdcontour with the dataarray
fig = pygmt.Figure()
fig.grdimage(grid, projection='W0/10c')
fig.grdcontour(grid, levels='-0.9,')
fig.show()
fig.savefig('grid1.png')

# Do the same using the netcdf file
fig2 = pygmt.Figure()
fig2.grdimage('grid.nc', projection='W0/10c')
fig2.grdcontour('grid.nc', levels='-0.9,')
fig2.show()
fig2.savefig('grid2.png')

Full error message

grdimage [WARNING]: Guessing of registration in conflict between x and y, using gridline
grdcontour [WARNING]: Guessing of registration in conflict between x and y, using gridline

System information

PyGMT information:
  version: v0.13.0
System information:
  python: 3.12.5 | packaged by conda-forge | (main, Aug  8 2024, 18:36:51) [GCC 12.4.0]
  executable: /home/mrak/miniforge3/envs/py312/bin/python
  machine: Linux-6.10.10-200.fc40.x86_64-x86_64-with-glibc2.39
Dependency information:
  numpy: 2.1.0
  pandas: 2.2.2
  xarray: 2024.7.0
  netCDF4: 1.7.1
  packaging: 24.1
  contextily: None
  geopandas: None
  IPython: 8.26.0
  rioxarray: None
  gdal: 3.9.2
  ghostscript: 10.03.1
GMT library information:
  version: 6.5.0
  padding: 2
  share dir: /home/mrak/miniforge3/envs/py312/share/gmt
  plugin dir: /home/mrak/miniforge3/envs/py312/lib/gmt/plugins
  library path: /home/mrak/miniforge3/envs/py312/lib/libgmt.so
  cores: 20
  grid layout: rows
  image layout: 
  binary version: 6.5.0