Skip to content

Commit 53b4e74

Browse files
authored
Explicitly use netcdf4 engine in xarray.open_dataarray to read grd files (#1264)
Using xr.open_datarray(..., engine="netcdf4") to read *.grd files, especially for the load_earth_relief function. Needed for xarray v0.18 due to backend API changes.
1 parent c795eeb commit 53b4e74

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

pygmt/datasets/earth_relief.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def load_earth_relief(resolution="01d", region=None, registration=None, use_srtm
133133
f"'region' is required for Earth relief resolution '{resolution}'."
134134
)
135135
fname = which(f"@earth_relief_{resolution}{reg}", download="a")
136-
with xr.open_dataarray(fname) as dataarray:
136+
with xr.open_dataarray(fname, engine="netcdf4") as dataarray:
137137
grid = dataarray.load()
138138
_ = grid.gmt # load GMTDataArray accessor information
139139
else:

pygmt/tests/test_accessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_accessor_pixel_geographic():
2424
and a gtype value of 0 when using Cartesian coordinates.
2525
"""
2626
fname = which(fname="@earth_relief_01d_p", download="a")
27-
grid = xr.open_dataarray(fname)
27+
grid = xr.open_dataarray(fname, engine="netcdf4")
2828
assert grid.gmt.registration == 1 # pixel registration
2929
assert grid.gmt.gtype == 1 # geographic coordinate type
3030

pygmt/tests/test_clib_put_matrix.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_put_matrix_grid():
9292
npt.assert_allclose(newdata, data)
9393

9494
# Save the data to a netCDF grid and check that xarray can load it
95-
with GMTTempFile() as tmp_grid:
95+
with GMTTempFile(suffix=".nc") as tmp_grid:
9696
lib.write_data(
9797
"GMT_IS_MATRIX",
9898
"GMT_IS_SURFACE",

0 commit comments

Comments
 (0)