From 242f92bfb42064a09c626b9f3f2a7890234b4a04 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 21 Nov 2022 09:51:12 -0500 Subject: [PATCH] load_earth_relief: Add the support of data source 'synbath' (#2162) * Add synbath option to earth_relief.py * Add tests for Earth relief with the synbath dataset * Update cache for synbath grids Co-authored-by: Dongdong Tian --- pygmt/datasets/earth_relief.py | 8 ++++++-- pygmt/helpers/testing.py | 3 +++ pygmt/tests/test_datasets_earth_relief.py | 25 +++++++++++++++++++---- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index 980f405337a..f4cbdf54015 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -141,11 +141,15 @@ def load_earth_relief( f"{registration}-registered Earth relief data for " f"resolution '{resolution}' is not supported." ) - earth_relief_sources = {"igpp": "earth_relief_", "gebco": "earth_gebco_"} + earth_relief_sources = { + "igpp": "earth_relief_", + "gebco": "earth_gebco_", + "synbath": "earth_synbath_", + } if data_source not in earth_relief_sources: raise GMTInvalidInput( f"Invalid earth relief 'data_source' {data_source}, " - "valid values are 'igpp' and 'gebco'." + "valid values are 'igpp', 'gebco', and 'synbath'." ) if data_source != "igpp": with Session() as lib: diff --git a/pygmt/helpers/testing.py b/pygmt/helpers/testing.py index 386d3bc7ad7..1af025e0d8e 100644 --- a/pygmt/helpers/testing.py +++ b/pygmt/helpers/testing.py @@ -164,6 +164,7 @@ def download_test_data(): "@earth_relief_10m_g", "@earth_relief_05m_p", "@earth_relief_05m_g", + "@earth_synbath_01d_g", # List of tiles of 03s srtm data. # Names like @N35E135.earth_relief_03s_g.nc is for internal use only. # The naming scheme may change. DO NOT USE IT IN YOUR SCRIPTS. @@ -172,6 +173,8 @@ def download_test_data(): "@N37W120.earth_relief_03s_g.nc", "@N00W090.earth_relief_03m_p.nc", "@N00E135.earth_relief_30s_g.nc", + # Earth synbath relief grids + "@S15W105.earth_synbath_30s_p.nc", # Earth seafloor age grids "@earth_age_01d_g", "@S90W180.earth_age_05m_g.nc", # Specific grid for 05m test diff --git a/pygmt/tests/test_datasets_earth_relief.py b/pygmt/tests/test_datasets_earth_relief.py index 3529e555df4..358818d2f0d 100644 --- a/pygmt/tests/test_datasets_earth_relief.py +++ b/pygmt/tests/test_datasets_earth_relief.py @@ -8,7 +8,7 @@ from pygmt.exceptions import GMTInvalidInput -@pytest.mark.parametrize("data_source", ["igpp", "gebco"]) +@pytest.mark.parametrize("data_source", ["igpp", "gebco", "synbath"]) def test_earth_relief_fails(data_source): """ Make sure earth relief fails for invalid resolutions. @@ -21,12 +21,14 @@ def test_earth_relief_fails(data_source): # Only test 01d and 30m to avoid downloading large datasets in CI -def test_earth_relief_01d_igpp(): +@pytest.mark.parametrize("data_source", ["igpp", "synbath"]) +def test_earth_relief_01d_igpp_synbath(data_source): """ - Test some properties of the earth relief 01d data with IGPP data. + Test some properties of the earth relief 01d data with IGPP and SYNBATH + data. """ data = load_earth_relief( - resolution="01d", registration="gridline", data_source="igpp" + resolution="01d", registration="gridline", data_source=data_source ) assert data.shape == (181, 361) npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) @@ -112,6 +114,21 @@ def test_earth_relief_05m_with_region(): assert data.sizes["lon"] == 481 +def test_earth_relief_30s_synbath(): + """ + Test some properties of the earth relief 30s data with SYNBATH data. + """ + data = load_earth_relief( + region=[-95, -94, -1.5, -1], + resolution="30s", + registration="pixel", + data_source="synbath", + ) + assert data.shape == (60, 120) + npt.assert_allclose(data.min(), -3552.5) + npt.assert_allclose(data.max(), -2154) + + def test_earth_relief_05m_without_region(): """ Test loading high-resolution earth relief without passing 'region'.