From 12d740315ed378176a294e277c57c1e53d19ab5c Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 16:56:39 +0100 Subject: [PATCH 01/16] Add remote dataset 'distance to shoreline' --- pygmt/datasets/earth_dist.py | 99 +++++++++++++++++++++++++ pygmt/datasets/load_remote_dataset.py | 18 +++++ pygmt/tests/test_datasets_earth_dist.py | 52 +++++++++++++ 3 files changed, 169 insertions(+) create mode 100755 pygmt/datasets/earth_dist.py create mode 100755 pygmt/tests/test_datasets_earth_dist.py diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py new file mode 100755 index 00000000000..48e671a0666 --- /dev/null +++ b/pygmt/datasets/earth_dist.py @@ -0,0 +1,99 @@ +""" +Function to download the GSHHG Earth distance to shoreline dataset from the GMT data server, and load +as :class:`xarray.DataArray`. + +The grids are available in various resolutions. +""" + +from collections.abc import Sequence +from typing import Literal + +import xarray as xr +from pygmt.datasets.load_remote_dataset import _load_remote_dataset + +__doctest_skip__ = ["load_earth_dist"] + + +def load_earth_geoid( + resolution: Literal[ + "01d", "30m", "20m", "15m", "10m", "06m", "05m", "04m", "03m", "02m", "01m" + ] = "01d", + region: Sequence[float] | str | None = None, + registration: Literal["gridline", "pixel"] = "gridline", +) -> xr.DataArray: + r""" + Load the GSHHG Earth distance to shoreline dataset in various resolutions. + + .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_dist.jpg + :width: 80 % + :align: center + + GSHHG Earth distance to shoreline dataset. + + The grids are downloaded to a user data directory (usually ``~/.gmt/server/earth/earth_dist/``) + the first time you invoke this function. Afterwards, it will load the grid from the data + directory. So you'll need an internet connection the first time around. + + These grids can also be accessed by passing in the file name **@earth_dist**\_\ *res*\[_\ *reg*] + to any grid processing function or plotting method. *res* is the grid resolution (see below), + and *reg* is the grid registration type (**p** for pixel registration or **g** for gridline + registration). + + The default color palette table (CPT) for this dataset is *earth_dist*. It's implicitly used when + passing in the file name of the dataset to any grid plotting method if no CPT is explicitl + specified. When the dataset is loaded and plotted as an :class:`xarray.DataArray` object, the + default CPT is ignored, and GMT's default CPT (*turbo*) is used. To use the dataset-specific CPT, + you need to explicitly set ``cmap="earth_dist"``. + + Refer to :gmt-datasets:`earth-dist.html` for more details about available datasets, including + version information and references. + + Parameters + ---------- + resolution + The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. + region + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, *ymin*, *ymax*] + or an ISO country code. Required for grids with resolutions higher than 5 arc-minutes (i.e., + ``"05m"``). + registration + Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for + gridline registration. + + Returns + ------- + grid + The Earth geoid grid. Coordinates are latitude and longitude in degrees. Units are in meters. + + Note + ---- + The registration and coordinate system type of the returned :class:`xarray.DataArray` grid can + be accessed via the GMT accessors (i.e., ``grid.gmt.registration`` and ``grid.gmt.gtype`` + respectively). However, these properties may be lost after specific grid operations (such as + slicing) and will need to be manually set before passing the grid to any PyGMT data processing + or plotting functions. Refer to :class:`pygmt.GMTDataArrayAccessor` for detailed explanations + and workarounds. + + Examples + -------- + + >>> from pygmt.datasets import load_earth_dist + >>> # load the default grid (gridline-registered 1 arc-degree grid) + >>> grid = load_earth_dist() + >>> # load the 30 arc-minutes grid with "gridline" registration + >>> grid = load_earth_dist(resolution="30m", registration="gridline") + >>> # load high-resolution (5 arc-minutes) grid for a specific region + >>> grid = load_earth_dist( + ... resolution="05m", + ... region=[120, 160, 30, 60], + ... registration="gridline", + ... ) + """ + grid = _load_remote_dataset( + name="earth_dist", + prefix="earth_dist", + resolution=resolution, + region=region, + registration=registration, + ) + return grid diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 168a93583b2..e6ada69c377 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -92,6 +92,24 @@ class GMTRemoteDataset(NamedTuple): "30s": Resolution("30s", registrations=["pixel"]), }, ), + "earth_dist": GMTRemoteDataset( + description="GSHHG Earth distance to shoreline", + units="???", + extra_attributes={"horizontal_datum": "WGS84"}, + resolutions={ + "01d": Resolution("01d"), + "30m": Resolution("30m"), + "20m": Resolution("20m"), + "15m": Resolution("15m"), + "10m": Resolution("10m"), + "06m": Resolution("06m"), + "05m": Resolution("05m", tiled=True), + "04m": Resolution("04m", tiled=True), + "03m": Resolution("03m", tiled=True), + "02m": Resolution("02m", tiled=True), + "01m": Resolution("01m", registrations=["gridline"], tiled=True), + }, + ), "earth_faa": GMTRemoteDataset( description="IGPP Earth free-air anomaly", units="mGal", diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py new file mode 100755 index 00000000000..b8ff14dc63e --- /dev/null +++ b/pygmt/tests/test_datasets_earth_dist.py @@ -0,0 +1,52 @@ +""" +Test basic functionality for loading Earth distance to shoreline datasets. +""" + +import numpy as np +import numpy.testing as npt +from pygmt.datasets import load_earth_dist + + +def test_earth_dist_01d(): + """ + Test some properties of the Earth distance to shoreline 01d data. + """ + data = load_earth_dist(resolution="01d") + assert data.name == "z" + assert data.attrs["description"] == "GSHHG Earth distance to shoreline" + assert data.attrs["units"] == "???" + 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.06, atol=0.01) + npt.assert_allclose(data.max(), 81.35, atol=0.01) + + +def test_earth_dist_01d_with_region(): + """ + Test loading low-resolution Earth distance to shoreline with "region". + """ + data = load_earth_dist(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(), 5.57, atol=0.01) + npt.assert_allclose(data.max(), 29.21, atol=0.01) + + +def test_earth_dist_01m_default_registration(): + """ + Test that the grid returned by default for the 1 arc-minute resolution has a "gridline" registration. + """ + data = load_earth_dist(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, atol=0.01) + npt.assert_allclose(data.max(), 30.04, atol=0.01) From 1497919f131e1e8c88d64c4098fc40315c10783a Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 17:07:10 +0100 Subject: [PATCH 02/16] Include 'distance to shoreline' dataset --- doc/api/index.rst | 1 + pygmt/datasets/__init__.py | 1 + pygmt/helpers/caching.py | 1 + 3 files changed, 3 insertions(+) diff --git a/doc/api/index.rst b/doc/api/index.rst index 07f76aff217..6c7025fd94c 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -233,6 +233,7 @@ and store them in GMT's user data directory. datasets.load_black_marble datasets.load_blue_marble datasets.load_earth_age + datasets.load_earth_dist datasets.load_earth_free_air_anomaly datasets.load_earth_geoid datasets.load_earth_magnetic_anomaly diff --git a/pygmt/datasets/__init__.py b/pygmt/datasets/__init__.py index d70eec5a1de..c557f03c466 100644 --- a/pygmt/datasets/__init__.py +++ b/pygmt/datasets/__init__.py @@ -6,6 +6,7 @@ from pygmt.datasets.earth_age import load_earth_age from pygmt.datasets.earth_day import load_blue_marble +from pygmt.datasets.earth_dist import load_earth_dist from pygmt.datasets.earth_free_air_anomaly import load_earth_free_air_anomaly from pygmt.datasets.earth_geoid import load_earth_geoid from pygmt.datasets.earth_magnetic_anomaly import load_earth_magnetic_anomaly diff --git a/pygmt/helpers/caching.py b/pygmt/helpers/caching.py index 26648b17060..a41d492f74e 100644 --- a/pygmt/helpers/caching.py +++ b/pygmt/helpers/caching.py @@ -14,6 +14,7 @@ def cache_data(): # List of GMT remote datasets. "@earth_age_01d_g", "@earth_day_01d", + "@earth_dist_01d", "@earth_faa_01d_g", "@earth_gebco_01d_g", "@earth_gebcosi_01d_g", From 1820add2faeeb607c385a759bbcd598926579176 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 17:29:28 +0100 Subject: [PATCH 03/16] Fix style | Fix typo --- pygmt/datasets/earth_dist.py | 2 +- pygmt/tests/test_datasets_earth_dist.py | 104 ++++++++++++------------ 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index 48e671a0666..e5a9a268f12 100755 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -14,7 +14,7 @@ __doctest_skip__ = ["load_earth_dist"] -def load_earth_geoid( +def load_earth_dist( resolution: Literal[ "01d", "30m", "20m", "15m", "10m", "06m", "05m", "04m", "03m", "02m", "01m" ] = "01d", diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py index b8ff14dc63e..30936eeb3d1 100755 --- a/pygmt/tests/test_datasets_earth_dist.py +++ b/pygmt/tests/test_datasets_earth_dist.py @@ -1,52 +1,52 @@ -""" -Test basic functionality for loading Earth distance to shoreline datasets. -""" - -import numpy as np -import numpy.testing as npt -from pygmt.datasets import load_earth_dist - - -def test_earth_dist_01d(): - """ - Test some properties of the Earth distance to shoreline 01d data. - """ - data = load_earth_dist(resolution="01d") - assert data.name == "z" - assert data.attrs["description"] == "GSHHG Earth distance to shoreline" - assert data.attrs["units"] == "???" - 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.06, atol=0.01) - npt.assert_allclose(data.max(), 81.35, atol=0.01) - - -def test_earth_dist_01d_with_region(): - """ - Test loading low-resolution Earth distance to shoreline with "region". - """ - data = load_earth_dist(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(), 5.57, atol=0.01) - npt.assert_allclose(data.max(), 29.21, atol=0.01) - - -def test_earth_dist_01m_default_registration(): - """ - Test that the grid returned by default for the 1 arc-minute resolution has a "gridline" registration. - """ - data = load_earth_dist(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, atol=0.01) - npt.assert_allclose(data.max(), 30.04, atol=0.01) +""" +Test basic functionality for loading Earth distance to shoreline datasets. +""" + +import numpy as np +import numpy.testing as npt +from pygmt.datasets import load_earth_dist + + +def test_earth_dist_01d(): + """ + Test some properties of the Earth distance to shoreline 01d data. + """ + data = load_earth_dist(resolution="01d") + assert data.name == "z" + assert data.attrs["description"] == "GSHHG Earth distance to shoreline" + assert data.attrs["units"] == "???" + 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.06, atol=0.01) + npt.assert_allclose(data.max(), 81.35, atol=0.01) + + +def test_earth_dist_01d_with_region(): + """ + Test loading low-resolution Earth distance to shoreline with "region". + """ + data = load_earth_dist(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(), 5.57, atol=0.01) + npt.assert_allclose(data.max(), 29.21, atol=0.01) + + +def test_earth_dist_01m_default_registration(): + """ + Test that the grid returned by default for the 1 arc-minute resolution has a "gridline" registration. + """ + data = load_earth_dist(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, atol=0.01) + npt.assert_allclose(data.max(), 30.04, atol=0.01) From bea3e73e6e27cf7a3646d3125379813f8e97d6de Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 19:17:37 +0100 Subject: [PATCH 04/16] Fix line length --- pygmt/datasets/earth_dist.py | 64 ++++++++++++++----------- pygmt/datasets/load_remote_dataset.py | 2 +- pygmt/tests/test_datasets_earth_dist.py | 5 +- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index e5a9a268f12..1485ee25bce 100755 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -1,6 +1,6 @@ """ -Function to download the GSHHG Earth distance to shoreline dataset from the GMT data server, and load -as :class:`xarray.DataArray`. +Function to download the GSHHG Earth distance to shoreline dataset from the GMT data +server, and loadas :class:`xarray.DataArray`. The grids are available in various resolutions. """ @@ -30,49 +30,55 @@ def load_earth_dist( GSHHG Earth distance to shoreline dataset. - The grids are downloaded to a user data directory (usually ``~/.gmt/server/earth/earth_dist/``) - the first time you invoke this function. Afterwards, it will load the grid from the data - directory. So you'll need an internet connection the first time around. + The grids are downloaded to a user data directory (usually + ``~/.gmt/server/earth/earth_dist/``) the first time you invoke this function. + Afterwards, it will load the grid from the data directory. So you'll need an + internet connection the first time around. - These grids can also be accessed by passing in the file name **@earth_dist**\_\ *res*\[_\ *reg*] - to any grid processing function or plotting method. *res* is the grid resolution (see below), - and *reg* is the grid registration type (**p** for pixel registration or **g** for gridline - registration). + These grids can also be accessed by passing in the file name + **@earth_dist**\_\ *res*\[_\ *reg*] to any grid processing function or plotting + method. *res* is the grid resolution (see below), and *reg* is the grid registration + type (**p** for pixel registration or **g** for gridline registration). - The default color palette table (CPT) for this dataset is *earth_dist*. It's implicitly used when - passing in the file name of the dataset to any grid plotting method if no CPT is explicitl - specified. When the dataset is loaded and plotted as an :class:`xarray.DataArray` object, the - default CPT is ignored, and GMT's default CPT (*turbo*) is used. To use the dataset-specific CPT, - you need to explicitly set ``cmap="earth_dist"``. + The default color palette table (CPT) for this dataset is *earth_dist*. It's + implicitly used when passing in the file name of the dataset to any grid plotting + method if no CPT is explicitly specified. When the dataset is loaded and plotted + as an :class:`xarray.DataArray` object, the default CPT is ignored, and GMT's + default CPT (*turbo*) is used. To use the dataset-specific CPT, you need to + explicitly set ``cmap="earth_dist"``. - Refer to :gmt-datasets:`earth-dist.html` for more details about available datasets, including - version information and references. + Refer to :gmt-datasets:`earth-dist.html` for more details about available datasets, + including version information and references. Parameters ---------- resolution - The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. + The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and + arc-minutes. region - The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, *ymin*, *ymax*] - or an ISO country code. Required for grids with resolutions higher than 5 arc-minutes (i.e., - ``"05m"``). + The subregion of the grid to load, in the form of a sequence + [*xmin*, *xmax*, *ymin*, *ymax*] + or an ISO country code. Required for grids with resolutions higher than 5 + arc-minutes (i.e., ``"05m"``). registration - Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for - gridline registration. + Grid registration type. Either ``"pixel"`` for pixel registration or + ``"gridline"`` for gridline registration. Returns ------- grid - The Earth geoid grid. Coordinates are latitude and longitude in degrees. Units are in meters. + The GSHHG Earth distance to shoreline grid. Coordinates are latitude and + longitude in degrees. Units are in XXX. Note ---- - The registration and coordinate system type of the returned :class:`xarray.DataArray` grid can - be accessed via the GMT accessors (i.e., ``grid.gmt.registration`` and ``grid.gmt.gtype`` - respectively). However, these properties may be lost after specific grid operations (such as - slicing) and will need to be manually set before passing the grid to any PyGMT data processing - or plotting functions. Refer to :class:`pygmt.GMTDataArrayAccessor` for detailed explanations - and workarounds. + The registration and coordinate system type of the returned + :class:`xarray.DataArray` grid can be accessed via the GMT accessors (i.e., + ``grid.gmt.registration`` and ``grid.gmt.gtype`` respectively). However, these + properties may be lost after specific grid operations (such as slicing) and will + need to be manually set before passing the grid to any PyGMT data processing or + plotting functions. Refer to :class:`pygmt.GMTDataArrayAccessor` for detailed + explanations and workarounds. Examples -------- diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index e6ada69c377..248cd4b6fea 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -94,7 +94,7 @@ class GMTRemoteDataset(NamedTuple): ), "earth_dist": GMTRemoteDataset( description="GSHHG Earth distance to shoreline", - units="???", + units="XXX", extra_attributes={"horizontal_datum": "WGS84"}, resolutions={ "01d": Resolution("01d"), diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py index 30936eeb3d1..abbdbbae9d5 100755 --- a/pygmt/tests/test_datasets_earth_dist.py +++ b/pygmt/tests/test_datasets_earth_dist.py @@ -14,7 +14,7 @@ def test_earth_dist_01d(): data = load_earth_dist(resolution="01d") assert data.name == "z" assert data.attrs["description"] == "GSHHG Earth distance to shoreline" - assert data.attrs["units"] == "???" + assert data.attrs["units"] == "XXX" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) assert data.gmt.registration == 0 @@ -39,7 +39,8 @@ def test_earth_dist_01d_with_region(): def test_earth_dist_01m_default_registration(): """ - Test that the grid returned by default for the 1 arc-minute resolution has a "gridline" registration. + Test that the grid returned by default for the 1 arc-minute resolution has a + "gridline" registration. """ data = load_earth_dist(resolution="01m", region=[-10, -9, 3, 5]) assert data.shape == (121, 61) From cea90749451f6a3c93e00bfccb1ab7c5e1d130be Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 19:22:27 +0100 Subject: [PATCH 05/16] Add unit --- pygmt/datasets/earth_dist.py | 4 ++-- pygmt/datasets/load_remote_dataset.py | 2 +- pygmt/tests/test_datasets_earth_dist.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index 1485ee25bce..b9dc9176189 100755 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -62,13 +62,13 @@ def load_earth_dist( arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or - ``"gridline"`` for gridline registration. + ``"gridline"`` for gridline registration. Returns ------- grid The GSHHG Earth distance to shoreline grid. Coordinates are latitude and - longitude in degrees. Units are in XXX. + longitude in degrees. Distances are in kilometers. Note ---- diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index 248cd4b6fea..717396c145c 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -94,7 +94,7 @@ class GMTRemoteDataset(NamedTuple): ), "earth_dist": GMTRemoteDataset( description="GSHHG Earth distance to shoreline", - units="XXX", + units="km", extra_attributes={"horizontal_datum": "WGS84"}, resolutions={ "01d": Resolution("01d"), diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py index abbdbbae9d5..e6b25d6513a 100755 --- a/pygmt/tests/test_datasets_earth_dist.py +++ b/pygmt/tests/test_datasets_earth_dist.py @@ -14,7 +14,7 @@ def test_earth_dist_01d(): data = load_earth_dist(resolution="01d") assert data.name == "z" assert data.attrs["description"] == "GSHHG Earth distance to shoreline" - assert data.attrs["units"] == "XXX" + assert data.attrs["units"] == "km" assert data.attrs["horizontal_datum"] == "WGS84" assert data.shape == (181, 361) assert data.gmt.registration == 0 From d4a176272e3def8f0b79b81d08a2be273dc71a90 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 19:30:22 +0100 Subject: [PATCH 06/16] Fix indent --- pygmt/datasets/earth_dist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index b9dc9176189..d77dee0f356 100755 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -54,7 +54,7 @@ def load_earth_dist( ---------- resolution The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and - arc-minutes. + arc-minutes. region The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, *ymin*, *ymax*] From 81a59bf3a3f8fd4caa6feb5ab601ce089c09b182 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 19:35:41 +0100 Subject: [PATCH 07/16] Fix indent --- pygmt/datasets/earth_dist.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index d77dee0f356..810dea1cac8 100755 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -56,10 +56,9 @@ def load_earth_dist( The grid resolution. The suffix ``d`` and ``m`` stand for arc-degrees and arc-minutes. region - The subregion of the grid to load, in the form of a sequence - [*xmin*, *xmax*, *ymin*, *ymax*] - or an ISO country code. Required for grids with resolutions higher than 5 - arc-minutes (i.e., ``"05m"``). + The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, + *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. From 98de2f99b3fd2bb97ac91182421c85c0c64f09c7 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 19:54:21 +0100 Subject: [PATCH 08/16] Remove tab --- pygmt/datasets/earth_dist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index 810dea1cac8..1ec678aceae 100755 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -58,7 +58,7 @@ def load_earth_dist( region The subregion of the grid to load, in the form of a sequence [*xmin*, *xmax*, *ymin*, *ymax*] or an ISO country code. Required for grids with resolutions - higher than 5 arc-minutes (i.e., ``"05m"``). + higher than 5 arc-minutes (i.e., ``"05m"``). registration Grid registration type. Either ``"pixel"`` for pixel registration or ``"gridline"`` for gridline registration. From e6a52f7219d3cfbf99897b8bd68fed8e426f3aa9 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 20:02:33 +0100 Subject: [PATCH 09/16] Remove execusion permission --- pygmt/datasets/earth_dist.py | 0 pygmt/tests/test_datasets_earth_dist.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 pygmt/datasets/earth_dist.py mode change 100755 => 100644 pygmt/tests/test_datasets_earth_dist.py diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py old mode 100755 new mode 100644 diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py old mode 100755 new mode 100644 From c7edcc19430fc9494c12f24fd2f36453ff412ec9 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 20:13:23 +0100 Subject: [PATCH 10/16] Adjust minimum values --- pygmt/tests/test_datasets_earth_dist.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py index e6b25d6513a..a143987df5f 100644 --- a/pygmt/tests/test_datasets_earth_dist.py +++ b/pygmt/tests/test_datasets_earth_dist.py @@ -20,7 +20,7 @@ def test_earth_dist_01d(): 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.06, atol=0.01) + npt.assert_allclose(data.min(), -2655.7, atol=0.01) npt.assert_allclose(data.max(), 81.35, atol=0.01) @@ -33,7 +33,7 @@ def test_earth_dist_01d_with_region(): 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(), 5.57, atol=0.01) + npt.assert_allclose(data.min(), -1081.94, atol=0.01) npt.assert_allclose(data.max(), 29.21, atol=0.01) @@ -49,5 +49,5 @@ def test_earth_dist_01m_default_registration(): 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, atol=0.01) + npt.assert_allclose(data.min(), -243.62, atol=0.01) npt.assert_allclose(data.max(), 30.04, atol=0.01) From 5e559442c0a41b220420e33b33e47e319753923d Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Sun, 22 Dec 2024 20:21:58 +0100 Subject: [PATCH 11/16] Adjust maximum values --- pygmt/tests/test_datasets_earth_dist.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py index a143987df5f..c5f9452c551 100644 --- a/pygmt/tests/test_datasets_earth_dist.py +++ b/pygmt/tests/test_datasets_earth_dist.py @@ -21,7 +21,7 @@ def test_earth_dist_01d(): 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(), -2655.7, atol=0.01) - npt.assert_allclose(data.max(), 81.35, atol=0.01) + npt.assert_allclose(data.max(), 2463.42, atol=0.01) def test_earth_dist_01d_with_region(): @@ -34,7 +34,7 @@ def test_earth_dist_01d_with_region(): 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(), -1081.94, atol=0.01) - npt.assert_allclose(data.max(), 29.21, atol=0.01) + npt.assert_allclose(data.max(), 105.17999, atol=0.01) def test_earth_dist_01m_default_registration(): @@ -50,4 +50,4 @@ def test_earth_dist_01m_default_registration(): assert data.coords["lon"].data.min() == -10.0 assert data.coords["lon"].data.max() == -9.0 npt.assert_allclose(data.min(), -243.62, atol=0.01) - npt.assert_allclose(data.max(), 30.04, atol=0.01) + npt.assert_allclose(data.max(), 2.939995, atol=0.01) From c9990bb0405a33c058a50730f62f352839235689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:49:50 +0100 Subject: [PATCH 12/16] Fix typos Co-authored-by: Dongdong Tian --- pygmt/datasets/earth_dist.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index 1ec678aceae..335fd53e977 100644 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -1,6 +1,6 @@ """ Function to download the GSHHG Earth distance to shoreline dataset from the GMT data -server, and loadas :class:`xarray.DataArray`. +server, and load as :class:`xarray.DataArray`. The grids are available in various resolutions. """ @@ -40,12 +40,12 @@ def load_earth_dist( method. *res* is the grid resolution (see below), and *reg* is the grid registration type (**p** for pixel registration or **g** for gridline registration). - The default color palette table (CPT) for this dataset is *earth_dist*. It's + The default color palette table (CPT) for this dataset is *@earth_dist.cpt*. It's implicitly used when passing in the file name of the dataset to any grid plotting method if no CPT is explicitly specified. When the dataset is loaded and plotted as an :class:`xarray.DataArray` object, the default CPT is ignored, and GMT's default CPT (*turbo*) is used. To use the dataset-specific CPT, you need to - explicitly set ``cmap="earth_dist"``. + explicitly set ``cmap="@earth_dist.cpt"``. Refer to :gmt-datasets:`earth-dist.html` for more details about available datasets, including version information and references. From 9ae76ed251e041b32b5cff688595f0cd46eff574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvonne=20Fr=C3=B6hlich?= <94163266+yvonnefroehlich@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:50:19 +0100 Subject: [PATCH 13/16] Round min max values Co-authored-by: Dongdong Tian --- pygmt/tests/test_datasets_earth_dist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/tests/test_datasets_earth_dist.py b/pygmt/tests/test_datasets_earth_dist.py index c5f9452c551..e0d91d77a84 100644 --- a/pygmt/tests/test_datasets_earth_dist.py +++ b/pygmt/tests/test_datasets_earth_dist.py @@ -34,7 +34,7 @@ def test_earth_dist_01d_with_region(): 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(), -1081.94, atol=0.01) - npt.assert_allclose(data.max(), 105.17999, atol=0.01) + npt.assert_allclose(data.max(), 105.18, atol=0.01) def test_earth_dist_01m_default_registration(): @@ -50,4 +50,4 @@ def test_earth_dist_01m_default_registration(): assert data.coords["lon"].data.min() == -10.0 assert data.coords["lon"].data.max() == -9.0 npt.assert_allclose(data.min(), -243.62, atol=0.01) - npt.assert_allclose(data.max(), 2.939995, atol=0.01) + npt.assert_allclose(data.max(), 2.94, atol=0.01) From 2404d9c0f2bd78c2c189553a34956da044cc5377 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Mon, 23 Dec 2024 22:54:06 +0100 Subject: [PATCH 14/16] Add nc file to caching --- pygmt/helpers/caching.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/helpers/caching.py b/pygmt/helpers/caching.py index a41d492f74e..183bab97161 100644 --- a/pygmt/helpers/caching.py +++ b/pygmt/helpers/caching.py @@ -46,6 +46,7 @@ def cache_data(): "@N00W030.earth_age_01m_g.nc", "@N30E060.earth_age_01m_g.nc", "@N30E090.earth_age_01m_g.nc", + "@N00W030.earth_dist_01m_g.nc", "@N00W030.earth_faa_01m_p.nc", "@N00W030.earth_geoid_01m_g.nc", "@S30W060.earth_mag_02m_p.nc", From 0682a1042b0bb123d2d092dc5da5a7536576aa98 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Tue, 24 Dec 2024 09:38:18 +0100 Subject: [PATCH 15/16] Explain sign of data --- pygmt/datasets/earth_dist.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index 335fd53e977..c4e7fa12c83 100644 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -67,7 +67,8 @@ def load_earth_dist( ------- grid The GSHHG Earth distance to shoreline grid. Coordinates are latitude and - longitude in degrees. Distances are in kilometers. + longitude in degrees. Distances are in kilometers, where positive (negative) + values mean land to coastline (ocean to coastline). Note ---- From 54aa002a24db27a6280f929a71b44ed2105bcb79 Mon Sep 17 00:00:00 2001 From: yvonnefroelich Date: Tue, 24 Dec 2024 09:59:36 +0100 Subject: [PATCH 16/16] Replace tab by white spaces --- pygmt/datasets/earth_dist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/datasets/earth_dist.py b/pygmt/datasets/earth_dist.py index c4e7fa12c83..4897c475b43 100644 --- a/pygmt/datasets/earth_dist.py +++ b/pygmt/datasets/earth_dist.py @@ -68,7 +68,7 @@ def load_earth_dist( grid The GSHHG Earth distance to shoreline grid. Coordinates are latitude and longitude in degrees. Distances are in kilometers, where positive (negative) - values mean land to coastline (ocean to coastline). + values mean land to coastline (ocean to coastline). Note ----