GenericMappingTools / GenericMappingTools/pygmt
deprecated `pygmt.load_dataarray()` inconsistent with `xr.load_datarray`
- Dominant language
- Python
- Stars
- 874
- Forks
- 255
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 40
Description
### Description of the problem
I'm not sure if this is a bug or a change to PyGMT which I missed. Since the `pygmt.load_dataarray` function is deprecated, I'm using the suggested alternative, `xr.load_datarray(..., engine="gmt", raster_kind='grid')`, however, this gives an incorrect grid registration.
As you can see below, a grid with a registration of 0 (gridline), when converted to pixle registered with `grdedit` and then opened again, gives the correct pixel registration (1) when using `pygmt.load_datarray`, but an incorrect gridline registration (0) when opened with `xr.load_dataarray`.
### Minimal Complete Verifiable Example
```python
import pygmt
import xarray as xr
grid = pygmt.datasets.load_earth_relief(
resolution="30s", region=[144.5, 145.5, 13, 14.5], registration="gridline"
)
print(grid.gmt.registration)
---> 0
with pygmt.clib.Session() as ses:
with ses.virtualfile_from_grid(grid) as f_in:
with pygmt.helpers.GMTTempFile(suffix=".nc") as tmpfile:
args = f"{f_in} -T -G{tmpfile.name}"
ses.call_module("grdedit", args)
f_out = pygmt.load_dataarray(tmpfile.name)
print(f_out.gmt.registration)
---> 1 # this is correct
with pygmt.clib.Session() as ses:
with ses.virtualfile_from_grid(grid) as f_in:
with pygmt.helpers.GMTTempFile(suffix=".nc") as tmpfile:
args = f"{f_in} -T -G{tmpfile.name}"
ses.call_module("grdedit", args)
f_out = xr.load_dataarray(tmpfile.name, engine='gmt', raster_kind='grid')
print(f_out.gmt.registration)
---> 0 # this is incorrect
```
### Full error message
```python-traceback
```
### System information
```bash
PyGMT information:
version: v0.16.0
System information:
python: 3.12.11 | packaged by conda-forge | (main, Jun 4 2025, 14:45:31) [GCC 13.3.0]
executable: /home/sungw937/miniforge3/envs/polartoolkit/bin/python
machine: Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.39
Dependency information:
numpy: 2.2.6
pandas: 2.3.1
xarray: 2025.7.1
packaging: 25.0
contextily: None
geopandas: 1.1.1
IPython: 9.4.0
pyarrow: 20.0.0
rioxarray: 0.19.0
gdal: None
ghostscript: 10.04.0
GMT library information:
version: 6.5.0
padding: 2
share dir: /home/sungw937/miniforge3/envs/polartoolkit/share/gmt
plugin dir: /home/sungw937/miniforge3/envs/polartoolkit/lib/gmt/plugins
library path: /home/sungw937/miniforge3/envs/polartoolkit/lib/libgmt.so
cores: 8
grid layout: rows
image layout:
binary version: 6.5.0
```
Contributor guide
Assessment
This issue has not been assessed yet.