Skip to content

Commit fdbc41a

Browse files
Add load_venus_relief to load Venus relief dataset in various resolutions (#2906)
Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent f7ad824 commit fdbc41a

File tree

6 files changed

+177
-0
lines changed

6 files changed

+177
-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_venus_relief
231232
datasets.load_sample_data
232233

233234
In addition, there is also a special function to load XYZ tile maps via

pygmt/datasets/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
from pygmt.datasets.moon_relief import load_moon_relief
1818
from pygmt.datasets.samples import list_sample_data, load_sample_data
1919
from pygmt.datasets.tile_map import load_tile_map
20+
from pygmt.datasets.venus_relief import load_venus_relief

pygmt/datasets/load_remote_dataset.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,26 @@ class GMTRemoteDataset(NamedTuple):
272272
"14s": Resolution("14s", registrations=["pixel"], tiled=True),
273273
},
274274
),
275+
"venus_relief": GMTRemoteDataset(
276+
title="Venus relief",
277+
name="venus_relief",
278+
long_name="NASA Magellan Venus 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", registrations=["gridline"], tiled=True),
293+
},
294+
),
275295
}
276296

277297

pygmt/datasets/venus_relief.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""
2+
Function to download the Venus 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_venus_relief"]
13+
14+
15+
@kwargs_to_strings(region="sequence")
16+
def load_venus_relief(
17+
resolution="01d",
18+
region=None,
19+
registration: Literal["gridline", "pixel"] = "gridline",
20+
):
21+
r"""
22+
Load the Venus relief dataset in various resolutions.
23+
24+
.. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_venus_relief.jpg
25+
:width: 80%
26+
:align: center
27+
28+
Venus relief dataset.
29+
30+
The grids are downloaded to a user data directory (usually
31+
``~/.gmt/server/venus/venus_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+
**@venus_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 *@venus_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="@venus_relief.cpt"``.
46+
47+
Refer to :gmt-datasets:`venus-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`` and ``m`` stand for arc-degrees and
54+
arc-minutes. It can be ``"01d"``, ``"30m"``, ``"20m"``, ``"15m"``, ``"10m"``,
55+
``"06m"``, ``"05m"``, ``"04m"``, ``"03m"``, ``"02m"``, and ``"01m"``.
56+
region : str or list
57+
The subregion of the grid to load, in the form of a list
58+
[*xmin*, *xmax*, *ymin*, *ymax*] or a string *xmin/xmax/ymin/ymax*.
59+
Required for grids with resolutions higher than 5 arc-minutes (i.e., ``"05m"``).
60+
registration
61+
Grid registration type. Either ``"pixel"`` for pixel registration or
62+
``"gridline"`` for gridline registration.
63+
64+
Returns
65+
-------
66+
grid : :class:`xarray.DataArray`
67+
The Venus relief grid. Coordinates are latitude and longitude in degrees. Relief
68+
is in meters.
69+
70+
Note
71+
----
72+
The registration and coordinate system type of the returned
73+
:class:`xarray.DataArray` grid can be accessed via the GMT accessors (i.e.,
74+
``grid.gmt.registration`` and ``grid.gmt.gtype`` respectively). However, these
75+
properties may be lost after specific grid operations (such as slicing) and will
76+
need to be manually set before passing the grid to any PyGMT data processing or
77+
plotting functions. Refer to :class:`pygmt.GMTDataArrayAccessor` for detailed
78+
explanations and workarounds.
79+
80+
Examples
81+
--------
82+
>>> from pygmt.datasets import load_venus_relief
83+
>>> # load the default grid (gridline-registered 1 arc-degree grid)
84+
>>> grid = load_venus_relief()
85+
>>> # load the 30 arc-minutes grid with "gridline" registration
86+
>>> grid = load_venus_relief(resolution="30m", registration="gridline")
87+
>>> # load high-resolution (5 arc-minutes) grid for a specific region
88+
>>> grid = load_venus_relief(
89+
... resolution="05m",
90+
... region=[120, 160, 30, 60],
91+
... registration="gridline",
92+
... )
93+
"""
94+
grid = _load_remote_dataset(
95+
dataset_name="venus_relief",
96+
dataset_prefix="venus_relief_",
97+
resolution=resolution,
98+
region=region,
99+
registration=registration,
100+
)
101+
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+
# Venus relief grids
69+
"@venus_relief_01d_g",
70+
"@N00W030.venus_relief_01m_g.nc", # Specific grid for 01m test
6871
# Other cache files
6972
"@capitals.gmt",
7073
"@circuit.png",
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 Venus relief datasets.
3+
"""
4+
import numpy as np
5+
import numpy.testing as npt
6+
from pygmt.datasets import load_venus_relief
7+
8+
9+
def test_venus_relief_01d():
10+
"""
11+
Test some properties of the Venus relief 01d data.
12+
"""
13+
data = load_venus_relief(resolution="01d")
14+
assert data.name == "venus_relief"
15+
assert data.attrs["units"] == "meters"
16+
assert data.attrs["long_name"] == "NASA Magellan Venus 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(), -2069.0, atol=0.5)
22+
npt.assert_allclose(data.max(), 9656.0, atol=0.5)
23+
24+
25+
def test_venus_relief_01d_with_region():
26+
"""
27+
Test loading low-resolution Venus relief with 'region'.
28+
"""
29+
data = load_venus_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(), -1244.0, atol=0.5)
35+
npt.assert_allclose(data.max(), -74.0, atol=0.5)
36+
37+
38+
def test_venus_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_venus_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(), -943.0, atol=0.5)
51+
npt.assert_allclose(data.max(), -192.5, atol=0.5)

0 commit comments

Comments
 (0)