|
9 | 9 | from pygmt._typing import PathLike |
10 | 10 | from pygmt.alias import Alias, AliasSystem |
11 | 11 | from pygmt.clib import Session |
| 12 | +from pygmt.exceptions import GMTInvalidInput |
12 | 13 | from pygmt.helpers import build_arg_list, fmt_docstring, use_alias |
13 | 14 |
|
14 | 15 | __doctest_skip__ = ["grdview"] |
|
19 | 20 | C="cmap", |
20 | 21 | G="drapegrid", |
21 | 22 | N="plane", |
22 | | - Q="surftype", |
23 | 23 | Wc="contourpen", |
24 | 24 | Wm="meshpen", |
25 | 25 | Wf="facadepen", |
|
30 | 30 | def grdview( # noqa: PLR0913 |
31 | 31 | self, |
32 | 32 | grid: PathLike | xr.DataArray, |
| 33 | + surftype: Literal[ |
| 34 | + "mesh", "surface", "surface+mesh", "image", "waterfallx", "waterfally" |
| 35 | + ] |
| 36 | + | None = None, |
| 37 | + dpi: int | None = None, |
| 38 | + meshfill: float | None = None, |
| 39 | + monochrome: bool = False, |
| 40 | + nan_transparent: bool = False, |
33 | 41 | projection: str | None = None, |
34 | 42 | zscale: float | str | None = None, |
35 | 43 | zsize: float | str | None = None, |
@@ -59,6 +67,7 @@ def grdview( # noqa: PLR0913 |
59 | 67 | - Jz = zscale |
60 | 68 | - JZ = zsize |
61 | 69 | - R = region |
| 70 | + - Q = surftype |
62 | 71 | - V = verbose |
63 | 72 | - c = panel |
64 | 73 | - p = perspective |
@@ -89,18 +98,24 @@ def grdview( # noqa: PLR0913 |
89 | 98 | Draw a plane at this z-level. If the optional color is provided via the **+g** |
90 | 99 | modifier, and the projection is not oblique, the frontal facade between the |
91 | 100 | plane and the data perimeter is colored. |
92 | | - surftype : str |
93 | | - Specify cover type of the grid. Select one of following settings: |
94 | | -
|
95 | | - - **m**: mesh plot [Default]. |
96 | | - - **mx** or **my**: waterfall plots (row or column profiles). |
97 | | - - **s**: surface plot, and optionally append **m** to have mesh lines drawn on |
98 | | - top of the surface. |
99 | | - - **i**: image plot. |
100 | | - - **c**: Same as **i** but will make nodes with z = NaN transparent. |
101 | | -
|
102 | | - For any of these choices, you may force a monochrome image by appending the |
103 | | - modifier **+m**. |
| 101 | + surftype |
| 102 | + Specify cover type of the grid. Valid values are: |
| 103 | +
|
| 104 | + - ``"mesh"``: mesh plot [Default]. |
| 105 | + - ``"surface``: surface plot. |
| 106 | + - ``"surface+mesh"``: surface plot with mesh lines drawn on top of the surface. |
| 107 | + - ``"image"``: image plot. |
| 108 | + - ``"waterfall_x"``/``"waterfall_y"``: waterfall plots (row or column profiles). |
| 109 | + dpi |
| 110 | + Effective dots-per-unit resolution for the rasterization for image plots (i.e., |
| 111 | + ``surftype="image"``) [Default is :gmt-term:`GMT_GRAPHICS_DPU`] |
| 112 | + meshfill |
| 113 | + For mesh plot or waterfall plots, set the mesh fill [Default is white]. |
| 114 | + monochrome |
| 115 | + Force conversion to monochrome image using the (television) YIQ transformation. |
| 116 | + nan_transparent |
| 117 | + Make grid nodes with z = NaN transparent, using the color-masking feature in |
| 118 | + PostScript Level 3. Only applies when ``surftype="image"``. |
104 | 119 | contourpen : str |
105 | 120 | Draw contour lines on top of surface or mesh (not image). Append pen attributes |
106 | 121 | used for the contours. |
@@ -159,9 +174,44 @@ def grdview( # noqa: PLR0913 |
159 | 174 | """ |
160 | 175 | self._activate_figure() |
161 | 176 |
|
| 177 | + if dpi is not None and surftype != "image": |
| 178 | + msg = "Parameter 'dpi' can only be used when 'surftype' is 'image'." |
| 179 | + raise GMTInvalidInput(msg) |
| 180 | + if nan_transparent and surftype != "image": |
| 181 | + msg = "Parameter 'nan_transparent' can only be used when 'surftype' is 'image'." |
| 182 | + raise GMTInvalidInput(msg) |
| 183 | + if meshfill is not None and surftype not in {"mesh", "waterfallx", "waterfally"}: |
| 184 | + msg = ( |
| 185 | + "Parameter 'meshfill' can only be used when 'surftype' is " |
| 186 | + "'mesh', 'waterfallx', or 'waterfally'." |
| 187 | + ) |
| 188 | + raise GMTInvalidInput(msg) |
| 189 | + |
| 190 | + _surtype_mapping = { |
| 191 | + "surface": "s", |
| 192 | + "mesh": "m", |
| 193 | + "surface+mesh": "sm", |
| 194 | + "image": "c" if nan_transparent is True else "i", |
| 195 | + "waterfallx": "mx", |
| 196 | + "waterfally": "my", |
| 197 | + } |
| 198 | + |
| 199 | + # surftype was aliased to Q previously. |
| 200 | + _old_surftype_syntax = surftype not in _surtype_mapping and surftype is not None |
| 201 | + |
162 | 202 | aliasdict = AliasSystem( |
163 | 203 | Jz=Alias(zscale, name="zscale"), |
164 | 204 | JZ=Alias(zsize, name="zsize"), |
| 205 | + Q=[ |
| 206 | + Alias( |
| 207 | + surftype, |
| 208 | + name="surftype", |
| 209 | + mapping=_surtype_mapping if not _old_surftype_syntax else None, |
| 210 | + ), |
| 211 | + Alias(dpi, name="dpi"), |
| 212 | + Alias(meshfill, name="meshfill"), |
| 213 | + Alias(monochrome, name="monochrome", prefix="+m"), |
| 214 | + ], |
165 | 215 | ).add_common( |
166 | 216 | B=frame, |
167 | 217 | J=projection, |
|
0 commit comments