Skip to content

Commit e4ee800

Browse files
seismanweiji14
andauthored
load_earth_mask: Keep data's encoding to correctly infer data's registration and gtype information (#2632)
Co-authored-by: Wei Ji <[email protected]>
1 parent 4dea40c commit e4ee800

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pygmt/datasets/earth_mask.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,7 @@ def load_earth_mask(resolution="01d", region=None, registration=None):
8989
region=region,
9090
registration=registration,
9191
)
92-
return grid.astype("int8")
92+
# `return grid.astype("int8")` doesn't work because grid encoding is lost.
93+
# See https://github.com/GenericMappingTools/pygmt/issues/2629.
94+
grid.data = grid.data.astype("int8")
95+
return grid

pygmt/tests/test_datasets_earth_mask.py

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_earth_mask_01d():
3737
assert data.attrs["horizontal_datum"] == "WGS84"
3838
assert data.shape == (181, 361)
3939
assert data.gmt.registration == 0
40+
assert data.gmt.gtype == 1
4041
assert data.dtype == "int8"
4142
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
4243
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
@@ -52,6 +53,8 @@ def test_earth_mask_01d_with_region():
5253
data = load_earth_mask(resolution="01d", region=[-7, 4, 13, 19])
5354
assert data.shape == (7, 12)
5455
assert data.gmt.registration == 0
56+
assert data.gmt.gtype == 1
57+
assert data.dtype == "int8"
5558
npt.assert_allclose(data.lat, np.arange(13, 20, 1))
5659
npt.assert_allclose(data.lon, np.arange(-7, 5, 1))
5760
npt.assert_allclose(data[1, 5], 1)

0 commit comments

Comments
 (0)