From aa8b4b09b41530dae254802a2c227549ea9a29b9 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 16 Aug 2023 11:19:46 +0800 Subject: [PATCH 1/3] load_earth_mask: Fix dataset's gtype information --- pygmt/datasets/earth_mask.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 From ed2b8bb18ed5c9ab952457f9cf7528b99363b050 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 16 Aug 2023 11:22:09 +0800 Subject: [PATCH 2/3] Add a test to make sure the mask grid is a Geographic grid --- pygmt/tests/test_datasets_earth_mask.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygmt/tests/test_datasets_earth_mask.py b/pygmt/tests/test_datasets_earth_mask.py index 27ded0e92a7..c2fc9b2afd0 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,7 @@ 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 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) From e1d335203139d4370c1458f684745fe7e7720020 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Wed, 16 Aug 2023 14:21:14 +0800 Subject: [PATCH 3/3] Update pygmt/tests/test_datasets_earth_mask.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/tests/test_datasets_earth_mask.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/tests/test_datasets_earth_mask.py b/pygmt/tests/test_datasets_earth_mask.py index c2fc9b2afd0..0f55b76aa10 100644 --- a/pygmt/tests/test_datasets_earth_mask.py +++ b/pygmt/tests/test_datasets_earth_mask.py @@ -54,6 +54,7 @@ def test_earth_mask_01d_with_region(): 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)