|
2 | 2 | Base class with plot generating commands.
|
3 | 3 | Does not define any special non-GMT methods (savefig, show, etc).
|
4 | 4 | """
|
| 5 | +import contextlib |
| 6 | + |
5 | 7 | from .clib import Session
|
6 | 8 | from .exceptions import GMTInvalidInput
|
7 | 9 | from .helpers import (
|
@@ -240,6 +242,7 @@ def grdimage(self, grid, **kwargs):
|
240 | 242 | JZ="zsize",
|
241 | 243 | B="frame",
|
242 | 244 | C="cmap",
|
| 245 | + G="drapegrid", |
243 | 246 | N="plane",
|
244 | 247 | Q="surftype",
|
245 | 248 | Wc="contourpen",
|
@@ -271,6 +274,13 @@ def grdview(self, reliefgrid, **kwargs):
|
271 | 274 | cmap (C) : str
|
272 | 275 | The name of the color palette table to use.
|
273 | 276 |
|
| 277 | + drapegrid (G) : str or xarray.DataArray |
| 278 | + The file name or a DataArray of the image grid to be draped on top of the |
| 279 | + relief provided by reliefgrid. [Default determines colors from reliefgrid]. |
| 280 | + Note that -Jz and -N always refers to the reliefgrid. The drapegrid only |
| 281 | + provides the information pertaining to colors, which (if drapegrid is a |
| 282 | + grid) will be looked-up via the CPT (see -C). |
| 283 | +
|
274 | 284 | plane (N) : float or str
|
275 | 285 | ``level[+gfill]``.
|
276 | 286 | Draws a plane at this z-level. If the optional color is provided via the +g
|
@@ -312,9 +322,22 @@ def grdview(self, reliefgrid, **kwargs):
|
312 | 322 | file_context = lib.virtualfile_from_grid(reliefgrid)
|
313 | 323 | else:
|
314 | 324 | raise GMTInvalidInput(
|
315 |
| - "Unrecognized data type: {}".format(type(reliefgrid)) |
| 325 | + f"Unrecognized data type for reliefgrid: {type(reliefgrid)}" |
316 | 326 | )
|
317 |
| - with file_context as fname: |
| 327 | + |
| 328 | + with contextlib.ExitStack() as stack: |
| 329 | + fname = stack.enter_context(file_context) |
| 330 | + if "G" in kwargs: |
| 331 | + drapegrid = kwargs["G"] |
| 332 | + if data_kind(drapegrid) in ("file", "grid"): |
| 333 | + if data_kind(drapegrid) == "grid": |
| 334 | + drape_context = lib.virtualfile_from_grid(drapegrid) |
| 335 | + drapefile = stack.enter_context(drape_context) |
| 336 | + kwargs["G"] = drapefile |
| 337 | + else: |
| 338 | + raise GMTInvalidInput( |
| 339 | + f"Unrecognized data type for drapegrid: {type(drapegrid)}" |
| 340 | + ) |
318 | 341 | arg_str = " ".join([fname, build_arg_string(kwargs)])
|
319 | 342 | lib.call_module("grdview", arg_str)
|
320 | 343 |
|
|
0 commit comments