|
| 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 |
0 commit comments