Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pygmt/src/grd2cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ def grd2cpt(grid, **kwargs):
"""
if kwargs.get("W") is not None and kwargs.get("Ww") is not None:
raise GMTInvalidInput("Set only categorical or cyclic to True, not both.")

if (output := kwargs.pop("H", None)) is not None:
kwargs["H"] = True

with Session() as lib:
with lib.virtualfile_in(check_kind="raster", data=grid) as vingrd:
if kwargs.get("H") is None: # if no output is set
arg_str = build_arg_list(kwargs, infile=vingrd)
else: # if output is set
outfile, kwargs["H"] = kwargs["H"], True
if not outfile or not isinstance(outfile, str):
raise GMTInvalidInput("'output' should be a proper file name.")
arg_str = build_arg_list(kwargs, infile=vingrd, outfile=outfile)
lib.call_module(module="grd2cpt", args=arg_str)
lib.call_module(
module="grd2cpt",
args=build_arg_list(kwargs, infile=vingrd, outfile=output),
)
17 changes: 7 additions & 10 deletions pygmt/src/makecpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,11 @@ def makecpt(**kwargs):
range. Note that ``cyclic=True`` cannot be set together with
``categorical=True``.
"""
if kwargs.get("W") is not None and kwargs.get("Ww") is not None:
raise GMTInvalidInput("Set only categorical or cyclic to True, not both.")

if (output := kwargs.pop("H", None)) is not None:
kwargs["H"] = True

with Session() as lib:
if kwargs.get("W") is not None and kwargs.get("Ww") is not None:
raise GMTInvalidInput("Set only categorical or cyclic to True, not both.")
if kwargs.get("H") is None: # if no output is set
arg_str = build_arg_list(kwargs)
else: # if output is set
outfile, kwargs["H"] = kwargs.pop("H"), True
if not outfile or not isinstance(outfile, str):
raise GMTInvalidInput("'output' should be a proper file name.")
arg_str = build_arg_list(kwargs, outfile=outfile)
lib.call_module(module="makecpt", args=arg_str)
lib.call_module(module="makecpt", args=build_arg_list(kwargs, outfile=output))