diff --git a/pygmt/datasets/earth_age.py b/pygmt/datasets/earth_age.py index 8b0fc50ec4e..a84fc93c733 100644 --- a/pygmt/datasets/earth_age.py +++ b/pygmt/datasets/earth_age.py @@ -44,9 +44,7 @@ def load_earth_age(resolution="01d", region=None, registration=None): registration : str Grid registration type. Either ``"pixel"`` for pixel registration or - ``"gridline"`` for gridline registration. Default is ``None``, where - a pixel-registered grid is returned unless only the - gridline-registered grid is available. + ``"gridline"`` for gridline registration. Default is ``"gridline"``. Returns ------- diff --git a/pygmt/datasets/earth_free_air_anomaly.py b/pygmt/datasets/earth_free_air_anomaly.py index afc94a4bbdf..a81b7e77895 100644 --- a/pygmt/datasets/earth_free_air_anomaly.py +++ b/pygmt/datasets/earth_free_air_anomaly.py @@ -44,9 +44,8 @@ def load_earth_free_air_anomaly(resolution="01d", region=None, registration=None registration : str Grid registration type. Either ``"pixel"`` for pixel registration or - ``"gridline"`` for gridline registration. Default is ``None``, where - a pixel-registered grid is returned unless only the - gridline-registered grid is available. + ``"gridline"`` for gridline registration. Default is ``"gridline"`` + for all resolutions except ``"01m"`` which is ``"pixel"`` only. Returns ------- diff --git a/pygmt/datasets/earth_geoid.py b/pygmt/datasets/earth_geoid.py index 87228ef771b..fa5d1ad020d 100644 --- a/pygmt/datasets/earth_geoid.py +++ b/pygmt/datasets/earth_geoid.py @@ -44,9 +44,7 @@ def load_earth_geoid(resolution="01d", region=None, registration=None): registration : str Grid registration type. Either ``"pixel"`` for pixel registration or - ``"gridline"`` for gridline registration. Default is ``None``, where - a pixel-registered grid is returned unless only the - gridline-registered grid is available. + ``"gridline"`` for gridline registration. Default is ``"gridline"``. Returns ------- diff --git a/pygmt/datasets/earth_magnetic_anomaly.py b/pygmt/datasets/earth_magnetic_anomaly.py index c7d010acf6b..0de1d9e52c6 100644 --- a/pygmt/datasets/earth_magnetic_anomaly.py +++ b/pygmt/datasets/earth_magnetic_anomaly.py @@ -49,9 +49,8 @@ def load_earth_magnetic_anomaly( registration : str Grid registration type. Either ``"pixel"`` for pixel registration or - ``"gridline"`` for gridline registration. Default is ``None``, where - a pixel-registered grid is returned unless only the - gridline-registered grid is available. + ``"gridline"`` for gridline registration. Default is ``"gridline"`` + for all resolutions except ``"02m"`` which is ``"pixel"`` only. mag4km : bool Choose the data version to use. The default is ``False``, which is diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index fe8937492a9..af12d59a301 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -57,12 +57,8 @@ def load_earth_relief( registration : str Grid registration type. Either ``"pixel"`` for pixel registration or - ``"gridline"`` for gridline registration. Default is ``None``, where - a gridline-registered grid is returned unless only the pixel-registered - grid is available. - - **Note**: For GMT 6.3, ``registration=None`` returns a pixel-registered - grid by default unless only the gridline-registered grid is available. + ``"gridline"`` for gridline registration. Default is ``"gridline"`` + for all resolutions except ``"15s"`` which is ``"pixel"`` only. data_source : str Select the source for the Earth relief data. diff --git a/pygmt/datasets/earth_vertical_gravity_gradient.py b/pygmt/datasets/earth_vertical_gravity_gradient.py index b47daad94c7..fde1e82ccaa 100644 --- a/pygmt/datasets/earth_vertical_gravity_gradient.py +++ b/pygmt/datasets/earth_vertical_gravity_gradient.py @@ -45,9 +45,8 @@ def load_earth_vertical_gravity_gradient( registration : str Grid registration type. Either ``"pixel"`` for pixel registration or - ``"gridline"`` for gridline registration. Default is ``None``, where - a pixel-registered grid is returned unless only the - gridline-registered grid is available. + ``"gridline"`` for gridline registration. Default is ``"gridline"`` + for all resolutions except ``"01m"`` which is ``"pixel"`` only. Returns ------- diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 014bd2a9baf..c5953e1c727 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -230,20 +230,26 @@ def _load_remote_dataset( The returned :class:`xarray.DataArray` doesn't support slice operation for tiled grids. """ - - if registration in ("pixel", "gridline", None): - # If None, let GMT decide on Pixel/Gridline type - reg = f"_{registration[0]}" if registration else "" + dataset = datasets[dataset_name] + if resolution not in dataset.resolutions.keys(): + raise GMTInvalidInput(f"Invalid resolution '{resolution}'.") + if registration is None: + # Check if "gridline" is an available registration for the resolution + if "gridline" in dataset.resolutions[resolution].registrations: + # Use default of gridline registration if available + registration = "gridline" + else: + registration = "pixel" + if registration in ("pixel", "gridline"): + reg = f"_{registration[0]}" else: raise GMTInvalidInput( f"Invalid grid registration: '{registration}', should be either " "'pixel', 'gridline' or None. Default is None, where a " - "pixel-registered grid is returned unless only the " - "gridline-registered grid is available." + "gridline-registered grid is returned unless only the " + "pixel-registered grid is available." ) - dataset = datasets[dataset_name] - if resolution not in dataset.resolutions.keys(): - raise GMTInvalidInput(f"Invalid resolution '{resolution}'.") + if registration and ( registration not in dataset.resolutions[resolution].registrations ): diff --git a/pygmt/helpers/testing.py b/pygmt/helpers/testing.py index 06eb3af0482..01395c86093 100644 --- a/pygmt/helpers/testing.py +++ b/pygmt/helpers/testing.py @@ -175,25 +175,26 @@ def download_test_data(): "@N37W120.earth_relief_03s_g.nc", "@N00W090.earth_relief_03m_p.nc", "@N00E135.earth_relief_30s_g.nc", + "@N00W010.earth_relief_15s_p.nc", # Specific grid for 15s test + "@N04W010.earth_relief_03s_g.nc", # Specific grid for 03s test # 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 + "@N00W030.earth_age_01m_g.nc", # Specific grid for 01m test # Earth geoid grids "@earth_geoid_01d_g", - "@S90W180.earth_geoid_05m_g.nc", # Specific grid for 05m test + "@N00W030.earth_geoid_01m_g.nc", # Specific grid for 01m test # Earth magnetic anomaly grids "@earth_mag_01d_g", - "@S90W180.earth_mag_05m_g.nc", # Specific grid for 05m test + "@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test "@earth_mag4km_01d_g", - "@S90W180.earth_mag4km_05m_g.nc", # Specific grid for 05m test # Earth free-air anomaly grids "@earth_faa_01d_g", - "@S90W180.earth_faa_05m_g.nc", # Specific grid for 05m test + "@N00W030.earth_faa_01m_p.nc", # Specific grid for 01m test # Earth vertical gravity gradient grids "@earth_vgg_01d_g", - "@S90W180.earth_vgg_05m_g.nc", # Specific grid for 05m test + "@N00W030.earth_vgg_01m_p.nc", # Specific grid for 01m test # Other cache files "@capitals.gmt", "@earth_relief_20m_holes.grd", diff --git a/pygmt/tests/test_datasets_earth_age.py b/pygmt/tests/test_datasets_earth_age.py index a3ebfdba409..b14c74352ca 100644 --- a/pygmt/tests/test_datasets_earth_age.py +++ b/pygmt/tests/test_datasets_earth_age.py @@ -31,12 +31,13 @@ def test_earth_age_01d(): """ Test some properties of the earth age 01d data. """ - data = load_earth_age(resolution="01d", registration="gridline") + data = load_earth_age(resolution="01d") assert data.name == "seafloor_age" assert data.attrs["units"] == "Myr" assert data.attrs["long_name"] == "age of seafloor crust" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), 0.167381, rtol=1e-5) @@ -47,39 +48,21 @@ def test_earth_age_01d_with_region(): """ Test loading low-resolution earth age with 'region'. """ - data = load_earth_age( - resolution="01d", region=[-10, 10, -5, 5], registration="gridline" - ) + data = load_earth_age(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), 11.293945) npt.assert_allclose(data.max(), 125.1189) -def test_earth_age_05m_with_region(): - """ - Test loading a subregion of high-resolution earth age. - """ - data = load_earth_age( - resolution="05m", region=[-50, -40, 20, 30], registration="gridline" - ) - assert data.coords["lat"].data.min() == 20.0 - assert data.coords["lat"].data.max() == 30.0 - assert data.coords["lon"].data.min() == -50.0 - assert data.coords["lon"].data.max() == -40.0 - npt.assert_allclose(data.data.min(), 0.040000916) - npt.assert_allclose(data.data.max(), 46.530003) - assert data.sizes["lat"] == 121 - assert data.sizes["lon"] == 121 - - -def test_earth_age_05m_without_region(): +def test_earth_age_01m_without_region(): """ Test loading high-resolution earth age without passing 'region'. """ with pytest.raises(GMTInvalidInput): - load_earth_age("05m") + load_earth_age("01m") def test_earth_age_incorrect_resolution_registration(): @@ -89,3 +72,19 @@ def test_earth_age_incorrect_resolution_registration(): """ with pytest.raises(GMTInvalidInput): load_earth_age(resolution="01m", region=[0, 1, 3, 5], registration="pixel") + + +def test_earth_age_01m_default_registration(): + """ + Test that the grid returned by default for the 1 arc-minute resolution has + a "gridline" registration. + """ + data = load_earth_age(resolution="01m", region=[-10, -9, 3, 5]) + assert data.shape == (121, 61) + assert data.gmt.registration == 0 + assert data.coords["lat"].data.min() == 3.0 + assert data.coords["lat"].data.max() == 5.0 + assert data.coords["lon"].data.min() == -10.0 + assert data.coords["lon"].data.max() == -9.0 + npt.assert_allclose(data.min(), 88.63) + npt.assert_allclose(data.max(), 125.25) diff --git a/pygmt/tests/test_datasets_earth_free_air_anomaly.py b/pygmt/tests/test_datasets_earth_free_air_anomaly.py index f2351e24c11..f9164ac2e50 100644 --- a/pygmt/tests/test_datasets_earth_free_air_anomaly.py +++ b/pygmt/tests/test_datasets_earth_free_air_anomaly.py @@ -31,12 +31,13 @@ def test_earth_faa_01d(): """ Test some properties of the free air anomaly 01d data. """ - data = load_earth_free_air_anomaly(resolution="01d", registration="gridline") + data = load_earth_free_air_anomaly(resolution="01d") assert data.name == "free_air_anomaly" assert data.attrs["long_name"] == "IGPP Global Earth Free-Air Anomaly" assert data.attrs["units"] == "mGal" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -275.75) @@ -47,36 +48,35 @@ def test_earth_faa_01d_with_region(): """ Test loading low-resolution earth free air anomaly with 'region'. """ - data = load_earth_free_air_anomaly( - resolution="01d", region=[-10, 10, -5, 5], registration="gridline" - ) + data = load_earth_free_air_anomaly(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -58.75) npt.assert_allclose(data.max(), 69.524994) -def test_earth_faa_05m_with_region(): +def test_earth_faa_01m_without_region(): """ - Test loading a subregion of high-resolution earth free air anomaly data. + Test loading high-resolution earth free air anomaly without passing + 'region'. """ - data = load_earth_free_air_anomaly( - resolution="05m", region=[-115, -112, 4, 6], registration="gridline" - ) - assert data.shape == (25, 37) - assert data.lat.min() == 4 - assert data.lat.max() == 6 - assert data.lon.min() == -115 - assert data.lon.max() == -112 - npt.assert_allclose(data.min(), -20.5) - npt.assert_allclose(data.max(), -3.9500122) + with pytest.raises(GMTInvalidInput): + load_earth_free_air_anomaly("01m") -def test_earth_faa_05m_without_region(): +def test_earth_faa_01m_default_registration(): """ - Test loading high-resolution earth free air anomaly without passing - 'region'. + Test that the grid returned by default for the 1 arc-minute resolution has + a "pixel" registration. """ - with pytest.raises(GMTInvalidInput): - load_earth_free_air_anomaly("05m") + data = load_earth_free_air_anomaly(resolution="01m", region=[-10, -9, 3, 5]) + assert data.shape == (120, 60) + assert data.gmt.registration == 1 + npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) + npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) + npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) + npt.assert_allclose(data.coords["lon"].data.max(), -9.00833333) + npt.assert_allclose(data.min(), -51) + npt.assert_allclose(data.max(), 113.675) diff --git a/pygmt/tests/test_datasets_earth_geoid.py b/pygmt/tests/test_datasets_earth_geoid.py index 281a5a957d9..2fdfcee2057 100644 --- a/pygmt/tests/test_datasets_earth_geoid.py +++ b/pygmt/tests/test_datasets_earth_geoid.py @@ -31,12 +31,13 @@ def test_earth_geoid_01d(): """ Test some properties of the earth geoid 01d data. """ - data = load_earth_geoid(resolution="01d", registration="gridline") + data = load_earth_geoid(resolution="01d") assert data.name == "earth_geoid" assert data.attrs["units"] == "m" assert data.attrs["long_name"] == "EGM2008 Global Earth Geoid" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -106.45) @@ -47,39 +48,21 @@ def test_earth_geoid_01d_with_region(): """ Test loading low-resolution earth geoid with 'region'. """ - data = load_earth_geoid( - resolution="01d", region=[-10, 10, -5, 5], registration="gridline" - ) + data = load_earth_geoid(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), 4.87) npt.assert_allclose(data.max(), 29.89) -def test_earth_geoid_05m_with_region(): - """ - Test loading a subregion of high-resolution earth geoid. - """ - data = load_earth_geoid( - resolution="05m", region=[-50, -40, 20, 30], registration="gridline" - ) - assert data.coords["lat"].data.min() == 20.0 - assert data.coords["lat"].data.max() == 30.0 - assert data.coords["lon"].data.min() == -50.0 - assert data.coords["lon"].data.max() == -40.0 - npt.assert_allclose(data.min(), -32.79) - npt.assert_allclose(data.max(), 16.57) - assert data.sizes["lat"] == 121 - assert data.sizes["lon"] == 121 - - -def test_earth_geoid_05m_without_region(): +def test_earth_geoid_01m_without_region(): """ Test loading high-resolution earth geoid without passing 'region'. """ with pytest.raises(GMTInvalidInput): - load_earth_geoid("05m") + load_earth_geoid("01m") def test_earth_geoid_incorrect_resolution_registration(): @@ -89,3 +72,19 @@ def test_earth_geoid_incorrect_resolution_registration(): """ with pytest.raises(GMTInvalidInput): load_earth_geoid(resolution="01m", region=[0, 1, 3, 5], registration="pixel") + + +def test_earth_geoid_01m_default_registration(): + """ + Test that the grid returned by default for the 1 arc-minute resolution has + a "gridline" registration. + """ + data = load_earth_geoid(resolution="01m", region=[-10, -9, 3, 5]) + assert data.shape == (121, 61) + assert data.gmt.registration == 0 + assert data.coords["lat"].data.min() == 3.0 + assert data.coords["lat"].data.max() == 5.0 + assert data.coords["lon"].data.min() == -10.0 + assert data.coords["lon"].data.max() == -9.0 + npt.assert_allclose(data.min(), 20.34) + npt.assert_allclose(data.max(), 30.039999) diff --git a/pygmt/tests/test_datasets_earth_magnetic_anomaly.py b/pygmt/tests/test_datasets_earth_magnetic_anomaly.py index 6c2f939ab55..3ba87eaa209 100644 --- a/pygmt/tests/test_datasets_earth_magnetic_anomaly.py +++ b/pygmt/tests/test_datasets_earth_magnetic_anomaly.py @@ -31,12 +31,13 @@ def test_earth_mag_01d(): """ Test some properties of the magnetic anomaly 01d data. """ - data = load_earth_magnetic_anomaly(resolution="01d", registration="gridline") + data = load_earth_magnetic_anomaly(resolution="01d") assert data.name == "magnetic_anomaly" assert data.attrs["long_name"] == "Earth magnetic anomaly" assert data.attrs["units"] == "nT" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -384) @@ -47,39 +48,22 @@ def test_earth_mag_01d_with_region(): """ Test loading low-resolution earth magnetic anomaly with 'region'. """ - data = load_earth_magnetic_anomaly( - resolution="01d", region=[-10, 10, -5, 5], registration="gridline" - ) + data = load_earth_magnetic_anomaly(resolution="01d", region=[-10, 10, -5, 5]) assert data.shape == (11, 21) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -180.40002) npt.assert_allclose(data.max(), 127.39996) -def test_earth_mag_05m_with_region(): - """ - Test loading a subregion of high-resolution earth magnetic anomaly data. - """ - data = load_earth_magnetic_anomaly( - resolution="05m", region=[-115, -112, 4, 6], registration="gridline" - ) - assert data.shape == (25, 37) - assert data.lat.min() == 4 - assert data.lat.max() == 6 - assert data.lon.min() == -115 - assert data.lon.max() == -112 - npt.assert_allclose(data.min(), -189.20001) - npt.assert_allclose(data.max(), 107) - - -def test_earth_mag_05m_without_region(): +def test_earth_mag_02m_without_region(): """ Test loading high-resolution earth magnetic anomaly without passing 'region'. """ with pytest.raises(GMTInvalidInput): - load_earth_magnetic_anomaly("05m") + load_earth_magnetic_anomaly("02m") def test_earth_mag_incorrect_resolution_registration(): @@ -97,14 +81,13 @@ def test_earth_mag4km_01d(): """ Test some properties of the magnetic anomaly 4km 01d data. """ - data = load_earth_magnetic_anomaly( - resolution="01d", registration="gridline", mag4km=True - ) + data = load_earth_magnetic_anomaly(resolution="01d", mag4km=True) assert data.name == "magnetic_anomaly" assert data.attrs["long_name"] == "Earth magnetic anomaly" assert data.attrs["units"] == "nT" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -799.19995) @@ -128,21 +111,17 @@ def test_earth_mag4km_01d_with_region(): npt.assert_allclose(data.max(), 113.59985) -def test_earth_mag4km_05m_with_region(): +def test_earth_mag_02m_default_registration(): """ - Test loading a subregion of high-resolution earth magnetic anomaly 4km - data. + Test that the grid returned by default for the 2 arc-minute resolution has + a "pixel" registration. """ - data = load_earth_magnetic_anomaly( - resolution="05m", - region=[-115, -112, 4, 6], - registration="gridline", - mag4km=True, - ) - assert data.shape == (25, 37) - assert data.lat.min() == 4 - assert data.lat.max() == 6 - assert data.lon.min() == -115 - assert data.lon.max() == -112 - npt.assert_allclose(data.min(), -128.40015) - npt.assert_allclose(data.max(), 76.80005) + data = load_earth_magnetic_anomaly(resolution="02m", region=[-10, -9, 3, 5]) + assert data.shape == (60, 30) + assert data.gmt.registration == 1 + npt.assert_allclose(data.coords["lat"].data.min(), 3.016666667) + npt.assert_allclose(data.coords["lat"].data.max(), 4.983333333) + npt.assert_allclose(data.coords["lon"].data.min(), -9.98333333) + npt.assert_allclose(data.coords["lon"].data.max(), -9.01666667) + npt.assert_allclose(data.min(), -231) + npt.assert_allclose(data.max(), 131.79999) diff --git a/pygmt/tests/test_datasets_earth_relief.py b/pygmt/tests/test_datasets_earth_relief.py index 5e6bfe02247..e8b176f491b 100644 --- a/pygmt/tests/test_datasets_earth_relief.py +++ b/pygmt/tests/test_datasets_earth_relief.py @@ -27,14 +27,13 @@ def test_earth_relief_01d_igpp_synbath(data_source): Test some properties of the earth relief 01d data with IGPP and SYNBATH data. """ - data = load_earth_relief( - resolution="01d", registration="gridline", data_source=data_source - ) + data = load_earth_relief(resolution="01d", data_source=data_source) assert data.name == "elevation" assert data.attrs["units"] == "meters" assert data.attrs["long_name"] == "Earth elevation relative to the geoid" assert data.attrs["vertical_datum"] == "EGM96" assert data.attrs["horizontal_datum"] == "WGS84" + assert data.gmt.registration == 0 assert data.shape == (181, 361) npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) @@ -48,10 +47,9 @@ def test_earth_relief_01d_gebco(data_source): Test some properties of the earth relief 01d data with GEBCO and GEBOCSI data. """ - data = load_earth_relief( - resolution="01d", registration="gridline", data_source=data_source - ) + data = load_earth_relief(resolution="01d", data_source=data_source) assert data.shape == (181, 361) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -8598) @@ -65,10 +63,10 @@ def test_earth_relief_01d_with_region_srtm(): data = load_earth_relief( resolution="01d", region=[-10, 10, -5, 5], - registration="gridline", data_source="igpp", ) assert data.shape == (11, 21) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -5154) @@ -82,10 +80,10 @@ def test_earth_relief_01d_with_region_gebco(): data = load_earth_relief( resolution="01d", region=[-10, 10, -5, 5], - registration="gridline", data_source="gebco", ) assert data.shape == (11, 21) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -5146) @@ -96,31 +94,15 @@ def test_earth_relief_30m(): """ Test some properties of the earth relief 30m data. """ - data = load_earth_relief(resolution="30m", registration="gridline") + data = load_earth_relief(resolution="30m") assert data.shape == (361, 721) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-90, 90.5, 0.5)) npt.assert_allclose(data.lon, np.arange(-180, 180.5, 0.5)) npt.assert_allclose(data.min(), -9454.5) npt.assert_allclose(data.max(), 5887.5) -def test_earth_relief_05m_with_region(): - """ - Test loading a subregion of high-resolution earth relief grid. - """ - data = load_earth_relief( - resolution="05m", region=[120, 160, 30, 60], registration="gridline" - ) - assert data.coords["lat"].data.min() == 30.0 - assert data.coords["lat"].data.max() == 60.0 - assert data.coords["lon"].data.min() == 120.0 - assert data.coords["lon"].data.max() == 160.0 - assert data.data.min() == -9633.0 - assert data.data.max() == 2532.0 - assert data.sizes["lat"] == 361 - assert data.sizes["lon"] == 481 - - def test_earth_gebcosi_15m_with_region(): """ Test loading a subregion of 15 arc-minutes resolution earth_gebcosi grid. @@ -132,6 +114,7 @@ def test_earth_gebcosi_15m_with_region(): data_source="gebcosi", ) assert data.shape == (16, 8) + assert data.gmt.registration == 1 npt.assert_allclose(data.lat, np.arange(-87.875, -84, 0.25)) npt.assert_allclose(data.lon, np.arange(85.125, 87, 0.25)) npt.assert_allclose(data.min(), -531) @@ -153,12 +136,12 @@ def test_earth_relief_30s_synbath(): npt.assert_allclose(data.max(), -2154) -def test_earth_relief_05m_without_region(): +def test_earth_relief_01m_without_region(): """ Test loading high-resolution earth relief without passing 'region'. """ with pytest.raises(GMTInvalidInput): - load_earth_relief("05m") + load_earth_relief("01m") def test_earth_relief_03s_landonly_srtm(): @@ -247,3 +230,35 @@ def test_earth_relief_incorrect_resolution_registration(data_source): registration="gridline", data_source=data_source, ) + + +def test_earth_relief_15s_default_registration(): + """ + Test that the grid returned by default for the 15 arc-second resolution has + a "pixel" registration. + """ + data = load_earth_relief(resolution="15s", region=[-10, -9.5, 4, 5]) + assert data.shape == (240, 120) + assert data.gmt.registration == 1 + npt.assert_allclose(data.coords["lat"].data.min(), 4.002083) + npt.assert_allclose(data.coords["lat"].data.max(), 4.997917) + npt.assert_allclose(data.coords["lon"].data.min(), -9.997917) + npt.assert_allclose(data.coords["lon"].data.max(), -9.502083) + npt.assert_allclose(data.min(), -3897) + npt.assert_allclose(data.max(), -74) + + +def test_earth_relief_03s_default_registration(): + """ + Test that the grid returned by default for the 3 arc-second resolution has + a "gridline" registration. + """ + data = load_earth_relief(resolution="03s", region=[-10, -9.8, 4.9, 5]) + assert data.shape == (121, 241) + assert data.gmt.registration == 0 + npt.assert_allclose(data.coords["lat"].data.min(), 4.9) + npt.assert_allclose(data.coords["lat"].data.max(), 5) + npt.assert_allclose(data.coords["lon"].data.min(), -10) + npt.assert_allclose(data.coords["lon"].data.max(), -9.8) + npt.assert_allclose(data.min(), -2069.996) + npt.assert_allclose(data.max(), -924.0801) diff --git a/pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py b/pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py index 2bbb85764d5..e9307d3742d 100644 --- a/pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py +++ b/pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py @@ -33,14 +33,13 @@ def test_earth_vertical_gravity_gradient_01d(): """ Test some properties of the earth vgg 01d data. """ - data = load_earth_vertical_gravity_gradient( - resolution="01d", registration="gridline" - ) + data = load_earth_vertical_gravity_gradient(resolution="01d") assert data.name == "earth_vgg" assert data.attrs["units"] == "Eotvos" assert data.attrs["long_name"] == "IGPP Global Earth Vertical Gravity Gradient" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-90, 91, 1)) npt.assert_allclose(data.lon, np.arange(-180, 181, 1)) npt.assert_allclose(data.min(), -136.34375) @@ -53,38 +52,22 @@ def test_earth_vertical_gravity_gradient_01d_with_region(): Test loading low-resolution earth vgg with 'region'. """ data = load_earth_vertical_gravity_gradient( - resolution="01d", region=[-10, 10, -5, 5], registration="gridline" + resolution="01d", region=[-10, 10, -5, 5] ) assert data.shape == (11, 21) + assert data.gmt.registration == 0 npt.assert_allclose(data.lat, np.arange(-5, 6, 1)) npt.assert_allclose(data.lon, np.arange(-10, 11, 1)) npt.assert_allclose(data.min(), -16.34375) npt.assert_allclose(data.max(), 19.78125) -def test_earth_vertical_gravity_gradient_05m_with_region(): - """ - Test loading a subregion of high-resolution earth vgg. - """ - data = load_earth_vertical_gravity_gradient( - resolution="05m", region=[-50, -40, 20, 26], registration="gridline" - ) - assert data.coords["lat"].data.min() == 20.0 - assert data.coords["lat"].data.max() == 26.0 - assert data.coords["lon"].data.min() == -50.0 - assert data.coords["lon"].data.max() == -40.0 - npt.assert_allclose(data.min(), -107.625) - npt.assert_allclose(data.max(), 159.75) - assert data.sizes["lat"] == 73 - assert data.sizes["lon"] == 121 - - -def test_earth_vertical_gravity_gradient_05m_without_region(): +def test_earth_vertical_gravity_gradient_01m_without_region(): """ Test loading high-resolution earth vgg without passing 'region'. """ with pytest.raises(GMTInvalidInput): - load_earth_vertical_gravity_gradient("05m") + load_earth_vertical_gravity_gradient("01m") def test_earth_vertical_gravity_gradient_incorrect_resolution_registration(): @@ -96,3 +79,21 @@ def test_earth_vertical_gravity_gradient_incorrect_resolution_registration(): load_earth_vertical_gravity_gradient( resolution="01m", region=[0, 1, 3, 5], registration="gridline" ) + + +def test_earth_vertical_gravity_gradient_01m_default_registration(): + """ + Test that the grid returned by default for the 1 arc-minute resolution has + a "pixel" registration. + """ + data = load_earth_vertical_gravity_gradient( + resolution="01m", region=[-10, -9, 3, 5] + ) + assert data.shape == (120, 60) + assert data.gmt.registration == 1 + npt.assert_allclose(data.coords["lat"].data.min(), 3.008333333) + npt.assert_allclose(data.coords["lat"].data.max(), 4.991666666) + npt.assert_allclose(data.coords["lon"].data.min(), -9.99166666) + npt.assert_allclose(data.coords["lon"].data.max(), -9.00833333) + npt.assert_allclose(data.min(), -40.25) + npt.assert_allclose(data.max(), 81.75)