From 41b6d58401e63dfb18acbc33ff0289805c2d76c5 Mon Sep 17 00:00:00 2001 From: Meghan Jones Date: Fri, 1 Apr 2022 11:32:33 -0400 Subject: [PATCH 1/8] Refactor nearneighbor --- pygmt/src/nearneighbor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index 1fe7e24bab8..c560b19605d 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -139,8 +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}) + if (outgrid := kwargs.get("G")) is None: # if outgrid is unset, output to tmpfile + kwargs["G"] = outgrid = tmpfile.name outgrid = kwargs["G"] arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module(module="nearneighbor", args=arg_str) From 32f4360da5b09bf2e935f22dccbb2a688912dcba Mon Sep 17 00:00:00 2001 From: Meghan Jones Date: Fri, 1 Apr 2022 11:32:46 -0400 Subject: [PATCH 2/8] Refactor sphdistance --- pygmt/src/sphdistance.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 63abe94e6e6..0d91a8d0313 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -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: # if outgrid is unset, output to tmpfile + kwargs["G"] = outgrid = tmpfile.name arg_str = build_arg_string(kwargs) arg_str = " ".join([infile, arg_str]) lib.call_module("sphdistance", arg_str) From a8012d62c67d4479d0eca1f23118b5f7f2044753 Mon Sep 17 00:00:00 2001 From: Meghan Jones Date: Fri, 1 Apr 2022 11:33:20 -0400 Subject: [PATCH 3/8] Add sphinterpolate --- pygmt/src/sphinterpolate.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/src/sphinterpolate.py b/pygmt/src/sphinterpolate.py index 15f49904aaa..0302beeaa66 100644 --- a/pygmt/src/sphinterpolate.py +++ b/pygmt/src/sphinterpolate.py @@ -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: # if outgrid is unset, output to tmpfile + kwargs["G"] = outgrid = tmpfile.name arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module("sphinterpolate", arg_str) From 868391810133186a2c1cb7c2ba9a6cf5db5d7137 Mon Sep 17 00:00:00 2001 From: Meghan Jones Date: Fri, 1 Apr 2022 11:33:32 -0400 Subject: [PATCH 4/8] Refactor surface --- pygmt/src/surface.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index c86ebc41e04..b12e0f8f671 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -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: # if outgrid is unset, output to tmpfile + kwargs["G"] = outgrid = tmpfile.name arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module(module="surface", args=arg_str) From 9619809f663abdce0c69f79fb0892b8590e469ba Mon Sep 17 00:00:00 2001 From: Meghan Jones Date: Fri, 1 Apr 2022 11:33:41 -0400 Subject: [PATCH 5/8] Refactor text --- pygmt/src/text.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index e7eac023cbd..b440627b0f4 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -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 @@ -215,7 +215,7 @@ def text_( extra_arrays = [] # If an array of transparency is given, GMT will read it from # the last numerical column per data record. - if "t" in kwargs and is_nonstr_iter(kwargs["t"]): + if kwargs.get("t") is not None and is_nonstr_iter(kwargs["t"]): extra_arrays.append(kwargs["t"]) kwargs["t"] = "" From 7195cbac71882e6df59b3411bef28fba49e23456 Mon Sep 17 00:00:00 2001 From: Meghan Jones Date: Fri, 1 Apr 2022 11:33:57 -0400 Subject: [PATCH 6/8] Refactor xyz2grd --- pygmt/src/xyz2grd.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 7deb42778ab..ae4e94250a8 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -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: # if outgrid is unset, output to tmpfile + kwargs["G"] = outgrid = tmpfile.name arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module("xyz2grd", arg_str) From 2f26ab488ef7369230f9ab4d0fb5a16a21d832a9 Mon Sep 17 00:00:00 2001 From: Meghan Jones Date: Fri, 1 Apr 2022 11:47:16 -0400 Subject: [PATCH 7/8] Remove redundant assignment --- pygmt/src/nearneighbor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index c560b19605d..bd3ce73232c 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -141,7 +141,6 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs): with table_context as infile: if (outgrid := kwargs.get("G")) is None: # if outgrid is unset, output to tmpfile kwargs["G"] = outgrid = tmpfile.name - outgrid = kwargs["G"] arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module(module="nearneighbor", args=arg_str) From 4a9a98e67eaf38f4cf9d6563ebe940fa6d521468 Mon Sep 17 00:00:00 2001 From: Meghan Jones Date: Fri, 1 Apr 2022 11:57:50 -0400 Subject: [PATCH 8/8] Format comments --- pygmt/src/nearneighbor.py | 4 ++-- pygmt/src/sphdistance.py | 4 ++-- pygmt/src/sphinterpolate.py | 4 ++-- pygmt/src/surface.py | 4 ++-- pygmt/src/xyz2grd.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index bd3ce73232c..7fecac95f47 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -139,8 +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 (outgrid := kwargs.get("G")) is None: # if outgrid is unset, output to tmpfile - kwargs["G"] = outgrid = tmpfile.name + if (outgrid := kwargs.get("G")) is None: + kwargs["G"] = outgrid = tmpfile.name # output to tmpfile arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module(module="nearneighbor", args=arg_str) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 0d91a8d0313..63f0da51d60 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -108,8 +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 (outgrid := kwargs.get("G")) is None: # if outgrid is unset, output to tmpfile - kwargs["G"] = outgrid = tmpfile.name + if (outgrid := kwargs.get("G")) is None: + kwargs["G"] = outgrid = tmpfile.name # output to tmpfile arg_str = build_arg_string(kwargs) arg_str = " ".join([infile, arg_str]) lib.call_module("sphdistance", arg_str) diff --git a/pygmt/src/sphinterpolate.py b/pygmt/src/sphinterpolate.py index 0302beeaa66..d6e476966e3 100644 --- a/pygmt/src/sphinterpolate.py +++ b/pygmt/src/sphinterpolate.py @@ -60,8 +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 (outgrid := kwargs.get("G")) is None: # if outgrid is unset, output to tmpfile - kwargs["G"] = outgrid = tmpfile.name + if (outgrid := kwargs.get("G")) is None: + kwargs["G"] = outgrid = tmpfile.name # output to tmpfile arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module("sphinterpolate", arg_str) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index b12e0f8f671..c0c35b15d1b 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -98,8 +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 (outgrid := kwargs.get("G")) is None: # if outgrid is unset, output to tmpfile - kwargs["G"] = outgrid = tmpfile.name + if (outgrid := kwargs.get("G")) is None: + kwargs["G"] = outgrid = tmpfile.name # output to tmpfile arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module(module="surface", args=arg_str) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index ae4e94250a8..6f45f3c7ba0 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -157,8 +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 (outgrid := kwargs.get("G")) is None: # if outgrid is unset, output to tmpfile - kwargs["G"] = outgrid = tmpfile.name + if (outgrid := kwargs.get("G")) is None: + kwargs["G"] = outgrid = tmpfile.name # output to tmpfile arg_str = " ".join([infile, build_arg_string(kwargs)]) lib.call_module("xyz2grd", arg_str)