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

problems with grdcontour when using xarray DataArrays #3479

Open
MarkWieczorek opened this issue Oct 1, 2024 · 0 comments
Open

problems with grdcontour when using xarray DataArrays #3479

MarkWieczorek opened this issue Oct 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@MarkWieczorek
Copy link
Contributor

MarkWieczorek commented Oct 1, 2024

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
@MarkWieczorek MarkWieczorek added the bug Something isn't working label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant