diff --git a/pygmt/datasets/earth_mask.py b/pygmt/datasets/earth_mask.py index 5b10357e5e8..371e0764dda 100644 --- a/pygmt/datasets/earth_mask.py +++ b/pygmt/datasets/earth_mask.py @@ -89,4 +89,7 @@ def load_earth_mask(resolution="01d", region=None, registration=None): region=region, registration=registration, ) - return grid.astype("int8") + # `return grid.astype("int8")` doesn't work because grid encoding is lost. + # See https://github.com/GenericMappingTools/pygmt/issues/2629. + grid.data = grid.data.astype("int8") + return grid diff --git a/pygmt/tests/test_datasets_earth_mask.py b/pygmt/tests/test_datasets_earth_mask.py index 27ded0e92a7..0f55b76aa10 100644 --- a/pygmt/tests/test_datasets_earth_mask.py +++ b/pygmt/tests/test_datasets_earth_mask.py @@ -37,6 +37,7 @@ def test_earth_mask_01d(): assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) assert data.gmt.registration == 0 + assert data.gmt.gtype == 1 assert data.dtype == "int8" npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) @@ -52,6 +53,8 @@ def test_earth_mask_01d_with_region(): data = load_earth_mask(resolution="01d", region=[-7, 4, 13, 19]) assert data.shape == (7, 12) assert data.gmt.registration == 0 + assert data.gmt.gtype == 1 + assert data.dtype == "int8" npt.assert_allclose(data.lat, np.arange(13, 20, 1)) npt.assert_allclose(data.lon, np.arange(-7, 5, 1)) npt.assert_allclose(data[1, 5], 1)