Skip to content

Commit 5d60a5d

Browse files
committed
Use the new way in Figure.grdview
1 parent 3ff29e4 commit 5d60a5d

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

pygmt/src/grdview.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,12 @@ def grdview(self, grid, **kwargs):
155155
"""
156156
kwargs = self._preprocess(**kwargs) # pylint: disable=protected-access
157157
with Session() as lib:
158-
file_context = lib.virtualfile_from_data(check_kind="raster", data=grid)
159-
160-
with contextlib.ExitStack() as stack:
161-
if kwargs.get("G") is not None:
162-
# deal with kwargs["G"] if drapegrid is xr.DataArray
163-
drapegrid = kwargs["G"]
164-
if data_kind(drapegrid) in ("file", "grid"):
165-
if data_kind(drapegrid) == "grid":
166-
drape_context = lib.virtualfile_from_data(
167-
check_kind="raster", data=drapegrid
168-
)
169-
kwargs["G"] = stack.enter_context(drape_context)
170-
else:
171-
raise GMTInvalidInput(
172-
f"Unrecognized data type for drapegrid: {type(drapegrid)}"
173-
)
174-
fname = stack.enter_context(file_context)
158+
with lib.virtualfile_from_data(
159+
check_kind="raster", data=grid
160+
) as fname, lib.virtualfile_from_data(
161+
check_kind="raster", data=kwargs.get("G"), optional_data=True
162+
) as drapegrid:
163+
kwargs["G"] = drapegrid
175164
lib.call_module(
176165
module="grdview", args=build_arg_string(kwargs, infile=fname)
177166
)

0 commit comments

Comments
 (0)