Skip to content

Commit

Permalink
Allow passing None explicitly to pygmt functions Part 2 (GenericMappi…
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrjones authored and Josh Sixsmith committed Dec 21, 2022
1 parent 28b050b commit d828a6d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
5 changes: 2 additions & 3 deletions pygmt/src/nearneighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs):
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
)
with table_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tmpfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module(
module="nearneighbor", args=build_arg_string(kwargs, infile=infile)
)
Expand Down
5 changes: 2 additions & 3 deletions pygmt/src/sphdistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ def sphdistance(data=None, x=None, y=None, **kwargs):
check_kind="vector", data=data, x=x, y=y
)
with file_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tempfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module("sphdistance", build_arg_string(kwargs, infile=infile))

return load_dataarray(outgrid) if outgrid == tmpfile.name else None
5 changes: 2 additions & 3 deletions pygmt/src/sphinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def sphinterpolate(data, **kwargs):
with Session() as lib:
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
with file_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tempfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module(
"sphinterpolate", build_arg_string(kwargs, infile=infile)
)
Expand Down
5 changes: 2 additions & 3 deletions pygmt/src/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ def surface(data=None, x=None, y=None, z=None, **kwargs):
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
)
with file_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tmpfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module(
module="surface", args=build_arg_string(kwargs, infile=infile)
)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def text_(
raise GMTInvalidInput("Must provide text with x/y pairs or position")

# Build the -F option in gmt text.
if "F" not in kwargs and (
if kwargs.get("F") is None and (
(
position is not None
or angle is not None
Expand Down
5 changes: 2 additions & 3 deletions pygmt/src/xyz2grd.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
)
with file_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tempfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module("xyz2grd", build_arg_string(kwargs, infile=infile))

return load_dataarray(outgrid) if outgrid == tmpfile.name else None

0 comments on commit d828a6d

Please sign in to comment.