Skip to content

Commit

Permalink
load_earth_relief: Add the support of data source 'synbath' (GenericM…
Browse files Browse the repository at this point in the history
…appingTools#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 <[email protected]>
  • Loading branch information
2 people authored and Josh Sixsmith committed Dec 21, 2022
1 parent a2cc42e commit 0d6be27
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
8 changes: 6 additions & 2 deletions pygmt/datasets/earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions pygmt/helpers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
25 changes: 21 additions & 4 deletions pygmt/tests/test_datasets_earth_relief.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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))
Expand Down Expand Up @@ -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'.
Expand Down

0 comments on commit 0d6be27

Please sign in to comment.