|
6 | 6 | from typing import Literal |
7 | 7 |
|
8 | 8 | import xarray as xr |
| 9 | +from packaging.version import Version |
9 | 10 | from pygmt._typing import PathLike |
10 | 11 | from pygmt.alias import Alias, AliasSystem |
11 | | -from pygmt.clib import Session |
| 12 | +from pygmt.clib import Session, __gmt_version__ |
12 | 13 | from pygmt.helpers import build_arg_list, deprecate_parameter, fmt_docstring, use_alias |
| 14 | +from pygmt.src.grdinfo import grdinfo |
13 | 15 |
|
14 | 16 | __doctest_skip__ = ["grdview"] |
15 | 17 |
|
@@ -116,6 +118,8 @@ def grdview( # noqa: PLR0913 |
116 | 118 | value in the grid. However, if ``region`` was used to set *zmin/zmax* then |
117 | 119 | *zmin* is used if it is less than the grid minimum value. Use ``facade_pen`` and |
118 | 120 | ``facade_fill`` to control the appearance of the plane. |
| 121 | + **Note**: For GMT<=6.6.0, *zmin* set in ``region`` has no effect due to a GMT |
| 122 | + bug. |
119 | 123 | facade_fill |
120 | 124 | Fill for the frontal facade between the plane specified by ``plane`` and the |
121 | 125 | data perimeter. |
@@ -174,6 +178,18 @@ def grdview( # noqa: PLR0913 |
174 | 178 | if plane is False and (facade_fill is not None or facade_pen is not None): |
175 | 179 | plane = True |
176 | 180 |
|
| 181 | + # Workaround for GMT bug https://github.com/GenericMappingTools/gmt/pull/8838 |
| 182 | + # Fix the plane value to be the grid minimum if plane=True. |
| 183 | + # Notes: |
| 184 | + # 1. It's the minimum of the grid, not a subset of the grid defined by 'region'. |
| 185 | + # 2. The GMT docs says "if -R was used to set zmin/zmax then we use that value if |
| 186 | + # it is less than the grid minimum value.". We can't add a workaround for this |
| 187 | + # case since we can't parse zmin/zmax from 'region' if 'region' was set in |
| 188 | + # previous plotting commands. |
| 189 | + # TODO(GMT>6.6.0): Remove this workaround. |
| 190 | + if Version(__gmt_version__) <= Version("6.6.0") and plane is True: |
| 191 | + plane = grdinfo(grid, per_column=True).split()[4] |
| 192 | + |
177 | 193 | aliasdict = AliasSystem( |
178 | 194 | Jz=Alias(zscale, name="zscale"), |
179 | 195 | JZ=Alias(zsize, name="zsize"), |
|
0 commit comments