Skip to content

Commit 598e770

Browse files
authored
Add load_pluto_relief to load Pluto relief dataset in various resolutions and registrations (#3027)
1 parent af22e94 commit 598e770

File tree

6 files changed

+181
-0
lines changed

6 files changed

+181
-0
lines changed

doc/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ and store them in GMT's user data directory.
228228
datasets.load_earth_vertical_gravity_gradient
229229
datasets.load_mars_relief
230230
datasets.load_moon_relief
231+
datasets.load_pluto_relief
231232
datasets.load_venus_relief
232233
datasets.load_sample_data
233234

pygmt/datasets/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from pygmt.datasets.mars_relief import load_mars_relief
1717
from pygmt.datasets.moon_relief import load_moon_relief
18+
from pygmt.datasets.pluto_relief import load_pluto_relief
1819
from pygmt.datasets.samples import list_sample_data, load_sample_data
1920
from pygmt.datasets.tile_map import load_tile_map
2021
from pygmt.datasets.venus_relief import load_venus_relief

pygmt/datasets/load_remote_dataset.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,27 @@ class GMTRemoteDataset(NamedTuple):
272272
"14s": Resolution("14s", registrations=["pixel"], tiled=True),
273273
},
274274
),
275+
"pluto_relief": GMTRemoteDataset(
276+
title="Pluto relief",
277+
name="pluto_relief",
278+
long_name="USGS Pluto relief",
279+
units="meters",
280+
extra_attributes={},
281+
resolutions={
282+
"01d": Resolution("01d"),
283+
"30m": Resolution("30m"),
284+
"20m": Resolution("20m"),
285+
"15m": Resolution("15m"),
286+
"10m": Resolution("10m"),
287+
"06m": Resolution("06m"),
288+
"05m": Resolution("05m", tiled=True),
289+
"04m": Resolution("04m", tiled=True),
290+
"03m": Resolution("03m", tiled=True),
291+
"02m": Resolution("02m", tiled=True),
292+
"01m": Resolution("01m", tiled=True),
293+
"52s": Resolution("52s", registrations=["pixel"], tiled=True),
294+
},
295+
),
275296
"venus_relief": GMTRemoteDataset(
276297
title="Venus relief",
277298
name="venus_relief",

pygmt/datasets/pluto_relief.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"""
2+
Function to download the Pluto relief dataset from the GMT data server, and load as
3+
:class:`xarray.DataArray`.
4+
5+
The grids are available in various resolutions.
6+
"""
7+
from typing import Literal
8+
9+
from pygmt.datasets.load_remote_dataset import _load_remote_dataset
10+
from pygmt.helpers import kwargs_to_strings
11+
12+
__doctest_skip__ = ["load_pluto_relief"]
13+
14+
15+
@kwargs_to_strings(region="sequence")
16+
def load_pluto_relief(
17+
resolution="01d",
18+
region=None,
19+
registration: Literal["gridline", "pixel", None] = None,
20+
):
21+
r"""
22+
Load the Pluto relief dataset in various resolutions.
23+
24+
.. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_pluto_relief.jpg
25+
:width: 80%
26+
:align: center
27+
28+
Pluto relief dataset.
29+
30+
The grids are downloaded to a user data directory (usually
31+
``~/.gmt/server/pluto/pluto_relief/``) the first time you invoke this function.
32+
Afterwards, it will load the grid from the data directory. So you'll need an
33+
internet connection the first time around.
34+
35+
These grids can also be accessed by passing in the file name
36+
**@pluto_relief**\_\ *res*\[_\ *reg*] to any grid processing function or plotting
37+
method. *res* is the grid resolution (see below), and *reg* is the grid registration
38+
type (**p** for pixel registration or **g** for gridline registration).
39+
40+
The default color palette table (CPT) for this dataset is *@pluto_relief.cpt*. It's
41+
implicitly used when passing in the file name of the dataset to any grid plotting
42+
method if no CPT is explicitly specified. When the dataset is loaded and plotted as
43+
an :class:`xarray.DataArray` object, the default CPT is ignored, and GMT's default
44+
CPT (*turbo*) is used. To use the dataset-specific CPT, you need to explicitly set
45+
``cmap="@pluto_relief.cpt"``.
46+
47+
Refer to :gmt-datasets:`pluto-relief.html` for more details about available
48+
datasets, including version information and references.
49+
50+
Parameters
51+
----------
52+
resolution : str
53+
The grid resolution. The suffix ``d``, ``m`` and ``s`` stand for arc-degrees,
54+
arc-minutes and arc-seconds. It can be ``"01d"``, ``"30m"``, ``"20m"``,
55+
``"15m"``, ``"10m"``, ``"06m"``, ``"05m"``, ``"04m"``, ``"03m"``, ``"02m"``,
56+
``"01m"``, and ``"52s"``.
57+
region : str or list
58+
The subregion of the grid to load, in the form of a list
59+
[*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*. Required for
60+
grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``).
61+
registration
62+
Grid registration type. Either ``"pixel"`` for pixel registration or
63+
``"gridline"`` for gridline registration. Default is ``None``, means
64+
``"gridline"`` for all resolutions except for ``"52s"`` which is ``"pixel"``
65+
only.
66+
67+
Returns
68+
-------
69+
grid : :class:`xarray.DataArray`
70+
The Pluto relief grid. Coordinates are latitude and longitude in degrees. Relief
71+
is in meters.
72+
73+
Note
74+
----
75+
The registration and coordinate system type of the returned
76+
:class:`xarray.DataArray` grid can be accessed via the GMT accessors (i.e.,
77+
``grid.gmt.registration`` and ``grid.gmt.gtype`` respectively). However, these
78+
properties may be lost after specific grid operations (such as slicing) and will
79+
need to be manually set before passing the grid to any PyGMT data processing or
80+
plotting functions. Refer to :class:`pygmt.GMTDataArrayAccessor` for detailed
81+
explanations and workarounds.
82+
83+
Examples
84+
--------
85+
>>> from pygmt.datasets import load_pluto_relief
86+
>>> # load the default grid (gridline-registered 1 arc-degree grid)
87+
>>> grid = load_pluto_relief()
88+
>>> # load the 30 arc-minutes grid with "gridline" registration
89+
>>> grid = load_pluto_relief(resolution="30m", registration="gridline")
90+
>>> # load high-resolution (5 arc-minutes) grid for a specific region
91+
>>> grid = load_pluto_relief(
92+
... resolution="05m",
93+
... region=[120, 160, 30, 60],
94+
... registration="gridline",
95+
... )
96+
"""
97+
grid = _load_remote_dataset(
98+
dataset_name="pluto_relief",
99+
dataset_prefix="pluto_relief_",
100+
resolution=resolution,
101+
region=region,
102+
registration=registration,
103+
)
104+
return grid

pygmt/helpers/caching.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def cache_data():
6565
# Moon relief grids
6666
"@moon_relief_01d_g",
6767
"@N00W030.moon_relief_01m_p.nc", # Specific grid for 01m test
68+
# Pluto relief grids
69+
"@pluto_relief_01d_g",
70+
"@N00W030.pluto_relief_01m_p.nc", # Specific grid for 01m test
6871
# Venus relief grids
6972
"@venus_relief_01d_g",
7073
"@N00W030.venus_relief_01m_g.nc", # Specific grid for 01m test
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Test basic functionality for loading Pluto relief datasets.
3+
"""
4+
import numpy as np
5+
import numpy.testing as npt
6+
from pygmt.datasets import load_pluto_relief
7+
8+
9+
def test_pluto_relief_01d():
10+
"""
11+
Test some properties of the Pluto relief 01d data.
12+
"""
13+
data = load_pluto_relief(resolution="01d")
14+
assert data.name == "pluto_relief"
15+
assert data.attrs["units"] == "meters"
16+
assert data.attrs["long_name"] == "USGS Pluto relief"
17+
assert data.shape == (181, 361)
18+
assert data.gmt.registration == 0
19+
npt.assert_allclose(data.lat, np.arange(-90, 91, 1))
20+
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
21+
npt.assert_allclose(data.min(), -3021.0, atol=0.25)
22+
npt.assert_allclose(data.max(), 4423.25, atol=0.25)
23+
24+
25+
def test_pluto_relief_01d_with_region():
26+
"""
27+
Test loading low-resolution Pluto relief with 'region'.
28+
"""
29+
data = load_pluto_relief(resolution="01d", region=[-10, 10, -5, 5])
30+
assert data.shape == (11, 21)
31+
assert data.gmt.registration == 0
32+
npt.assert_allclose(data.lat, np.arange(-5, 6, 1))
33+
npt.assert_allclose(data.lon, np.arange(-10, 11, 1))
34+
npt.assert_allclose(data.min(), -1319.25, atol=0.25)
35+
npt.assert_allclose(data.max(), 27.5, atol=0.25)
36+
37+
38+
def test_pluto_relief_01m_default_registration():
39+
"""
40+
Test that the grid returned by default for the 1 arc-minute resolution has
41+
a "gridline" registration.
42+
"""
43+
data = load_pluto_relief(resolution="01m", region=[-10, -9, 3, 5])
44+
assert data.shape == (121, 61)
45+
assert data.gmt.registration == 0
46+
assert data.coords["lat"].data.min() == 3.0
47+
assert data.coords["lat"].data.max() == 5.0
48+
assert data.coords["lon"].data.min() == -10.0
49+
assert data.coords["lon"].data.max() == -9.0
50+
npt.assert_allclose(data.min(), -1280.5, atol=0.25)
51+
npt.assert_allclose(data.max(), 1665.0, atol=0.25)

0 commit comments

Comments
 (0)