From de206a37c745cc030af3b21c5a0cb9a9b81d8840 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 10 Sep 2021 19:59:57 -0400 Subject: [PATCH 01/17] Add table docstring to parameters list --- pygmt/src/sphdistance.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 14883e57ce0..407a12afd54 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -35,6 +35,10 @@ def sphdistance(table, **kwargs): Parameters ---------- + table : str or {table-like} + Pass in (x, y, z) or (longitude, latitude, elevation) values by + providing a file name to an ASCII data table, a 2D + {table-classes}. outgrid : str or None The name of the output netCDF file with extension .nc to store the grid in. From 0e41a097ab2b2ace0f1d6e4f772a2de39443ea3e Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 10 Sep 2021 20:02:45 -0400 Subject: [PATCH 02/17] move sphdistance to tabular data section --- doc/api/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/index.rst b/doc/api/index.rst index 0426f79385d..5135936011a 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -81,6 +81,7 @@ Operations on tabular data: blockmean blockmedian + sphdistance surface Operations on grids: @@ -97,7 +98,6 @@ Operations on grids: grdproject grdsample grdtrack - sphdistance xyz2grd Crossover analysis with x2sys: From 68fcb68aa2038f7b8eae4137343dcf2636a081e0 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Sep 2021 08:26:04 +0100 Subject: [PATCH 03/17] Update pygmt/src/sphdistance.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/sphdistance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 407a12afd54..b08368a0fc2 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -35,7 +35,7 @@ def sphdistance(table, **kwargs): Parameters ---------- - table : str or {table-like} + data : str or {table-like} Pass in (x, y, z) or (longitude, latitude, elevation) values by providing a file name to an ASCII data table, a 2D {table-classes}. From 9422b5138b6b34857fead04326109931f97a2216 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Sep 2021 08:30:59 +0100 Subject: [PATCH 04/17] change "table" to "data" --- pygmt/src/sphdistance.py | 4 ++-- pygmt/tests/test_sphdistance.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index b08368a0fc2..0dcd9fd0fdf 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -22,7 +22,7 @@ V="verbose", ) @kwargs_to_strings(I="sequence", R="sequence") -def sphdistance(table, **kwargs): +def sphdistance(data, **kwargs): r""" Create Voroni polygons from lat/lon coordinates. @@ -58,7 +58,7 @@ def sphdistance(table, **kwargs): raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.") with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=table) + file_context = lib.virtualfile_from_data(check_kind="vector", data=data) with file_context as infile: if "G" not in kwargs.keys(): # if outgrid is unset, output to tempfile kwargs.update({"G": tmpfile.name}) diff --git a/pygmt/tests/test_sphdistance.py b/pygmt/tests/test_sphdistance.py index ebdbb13dc2b..9bd96b3c3f8 100644 --- a/pygmt/tests/test_sphdistance.py +++ b/pygmt/tests/test_sphdistance.py @@ -26,7 +26,7 @@ def test_sphdistance_outgrid(array): """ with GMTTempFile(suffix=".nc") as tmpfile: result = sphdistance( - table=array, outgrid=tmpfile.name, spacing=1, region=[82, 87, 22, 24] + data=array, outgrid=tmpfile.name, spacing=1, region=[82, 87, 22, 24] ) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists @@ -36,7 +36,7 @@ def test_sphdistance_no_outgrid(array): """ Test sphdistance with no set outgrid. """ - temp_grid = sphdistance(table=array, spacing=[1, 2], region=[82, 87, 22, 24]) + temp_grid = sphdistance(data=array, spacing=[1, 2], region=[82, 87, 22, 24]) assert temp_grid.dims == ("lat", "lon") assert temp_grid.gmt.gtype == 1 # Geographic grid assert temp_grid.gmt.registration == 0 # Gridline registration @@ -52,4 +52,4 @@ def test_sphdistance_fails(array): given. """ with pytest.raises(GMTInvalidInput): - sphdistance(table=array) + sphdistance(data=array) From 10a1aeeb648e5e7058cb643961a2935a741582da Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Sep 2021 08:33:04 +0100 Subject: [PATCH 05/17] add blank line to prevent Sphinx error --- pygmt/src/sphdistance.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 0dcd9fd0fdf..28efd2f0a1c 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -50,6 +50,7 @@ def sphdistance(data, **kwargs): ------- ret: xarray.DataArray or None Return type depends on whether the ``outgrid`` parameter is set: + - :class:`xarray.DataArray` if ``outgrid`` is not set - None if ``outgrid`` is set (grid output will be stored in file set by ``outgrid``) From 663805fceff1b8a8a223881671c976b064befd07 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 23 Sep 2021 08:34:45 +0100 Subject: [PATCH 06/17] run make format --- pygmt/src/sphdistance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 28efd2f0a1c..d5ef0fa7f11 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -50,7 +50,7 @@ def sphdistance(data, **kwargs): ------- ret: xarray.DataArray or None Return type depends on whether the ``outgrid`` parameter is set: - + - :class:`xarray.DataArray` if ``outgrid`` is not set - None if ``outgrid`` is set (grid output will be stored in file set by ``outgrid``) From b1d573fa7605c98184b28bbdfab9f987c6120f6d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 25 Sep 2021 07:23:02 +0100 Subject: [PATCH 07/17] add parameters for xy input --- pygmt/src/sphdistance.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index d5ef0fa7f11..6485d9ab2b2 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -22,7 +22,7 @@ V="verbose", ) @kwargs_to_strings(I="sequence", R="sequence") -def sphdistance(data, **kwargs): +def sphdistance(x=None, y=None, z=None, data=None, **kwargs): r""" Create Voroni polygons from lat/lon coordinates. @@ -35,6 +35,8 @@ def sphdistance(data, **kwargs): Parameters ---------- + x/y/z : 1d arrays + Arrays of x and y coordinates and values z of the data points. data : str or {table-like} Pass in (x, y, z) or (longitude, latitude, elevation) values by providing a file name to an ASCII data table, a 2D @@ -59,7 +61,9 @@ def sphdistance(data, **kwargs): raise GMTInvalidInput("Both 'region' and 'spacing' must be specified.") with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: - file_context = lib.virtualfile_from_data(check_kind="vector", data=data) + file_context = lib.virtualfile_from_data( + check_kind="vector", data=data, x=x, y=y, z=z + ) with file_context as infile: if "G" not in kwargs.keys(): # if outgrid is unset, output to tempfile kwargs.update({"G": tmpfile.name}) From d43419522640478754cf1ada8bad34042dfe2ad7 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 25 Sep 2021 07:23:10 +0100 Subject: [PATCH 08/17] add test for xy inputs --- pygmt/tests/test_sphdistance.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pygmt/tests/test_sphdistance.py b/pygmt/tests/test_sphdistance.py index 9bd96b3c3f8..5a61171e749 100644 --- a/pygmt/tests/test_sphdistance.py +++ b/pygmt/tests/test_sphdistance.py @@ -20,6 +20,22 @@ def fixture_table(): return np.array(coords_list) +def test_sphdistance_xy_inputs(): + """ + Test inputs using separate xy arguments. + """ + y = [22.3, 22.6, 22.4, 23.3] + x = [85.5, 82.3, 85.8, 86.5] + temp_grid = sphdistance(x=x, y=y, spacing=[1, 2], region=[82, 87, 22, 24]) + assert temp_grid.dims == ("lat", "lon") + assert temp_grid.gmt.gtype == 1 # Geographic grid + assert temp_grid.gmt.registration == 0 # Gridline registration + npt.assert_allclose(temp_grid.max(), 232977.546875) + npt.assert_allclose(temp_grid.min(), 0) + npt.assert_allclose(temp_grid.median(), 0) + npt.assert_allclose(temp_grid.mean(), 62469.17) + + def test_sphdistance_outgrid(array): """ Test sphdistance with a set outgrid. From 24a3c2a42cf482858ec6dc7ccd775b5ca80d0afc Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 26 Sep 2021 08:08:18 +0100 Subject: [PATCH 09/17] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/src/sphdistance.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 6485d9ab2b2..3f3db6c4ed9 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -22,7 +22,7 @@ V="verbose", ) @kwargs_to_strings(I="sequence", R="sequence") -def sphdistance(x=None, y=None, z=None, data=None, **kwargs): +def sphdistance(data=None, x=None, y=None, z=None, **kwargs): r""" Create Voroni polygons from lat/lon coordinates. @@ -35,12 +35,12 @@ def sphdistance(x=None, y=None, z=None, data=None, **kwargs): Parameters ---------- - x/y/z : 1d arrays - Arrays of x and y coordinates and values z of the data points. data : str or {table-like} Pass in (x, y, z) or (longitude, latitude, elevation) values by providing a file name to an ASCII data table, a 2D {table-classes}. + x/y/z : 1d arrays + Arrays of x and y coordinates and values z of the data points. outgrid : str or None The name of the output netCDF file with extension .nc to store the grid in. @@ -62,7 +62,7 @@ def sphdistance(x=None, y=None, z=None, data=None, **kwargs): with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: file_context = lib.virtualfile_from_data( - check_kind="vector", data=data, x=x, y=y, z=z + check_kind="vector", data=data, x=x, y=y, z=z, required_z=True ) with file_context as infile: if "G" not in kwargs.keys(): # if outgrid is unset, output to tempfile From 7db2128424307088699375668f87f5ede2ecc1dc Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 26 Sep 2021 10:30:42 +0100 Subject: [PATCH 10/17] remove z parameter --- pygmt/src/sphdistance.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 3f3db6c4ed9..1ea1c64969d 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -22,7 +22,7 @@ V="verbose", ) @kwargs_to_strings(I="sequence", R="sequence") -def sphdistance(data=None, x=None, y=None, z=None, **kwargs): +def sphdistance(data=None, x=None, y=None, **kwargs): r""" Create Voroni polygons from lat/lon coordinates. @@ -36,7 +36,7 @@ def sphdistance(data=None, x=None, y=None, z=None, **kwargs): Parameters ---------- data : str or {table-like} - Pass in (x, y, z) or (longitude, latitude, elevation) values by + Pass in (x, y) or (longitude, latitude) values by providing a file name to an ASCII data table, a 2D {table-classes}. x/y/z : 1d arrays @@ -62,7 +62,7 @@ def sphdistance(data=None, x=None, y=None, z=None, **kwargs): with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: file_context = lib.virtualfile_from_data( - check_kind="vector", data=data, x=x, y=y, z=z, required_z=True + check_kind="vector", data=data, x=x, y=y ) with file_context as infile: if "G" not in kwargs.keys(): # if outgrid is unset, output to tempfile From b9591f8348ef1b2ad16b129e5e630fbca670fd5e Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 27 Sep 2021 07:51:37 +0100 Subject: [PATCH 11/17] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/src/sphdistance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 1ea1c64969d..e701e307ffb 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -39,8 +39,8 @@ def sphdistance(data=None, x=None, y=None, **kwargs): Pass in (x, y) or (longitude, latitude) values by providing a file name to an ASCII data table, a 2D {table-classes}. - x/y/z : 1d arrays - Arrays of x and y coordinates and values z of the data points. + x/y : 1d arrays + Arrays of x and y coordinates. outgrid : str or None The name of the output netCDF file with extension .nc to store the grid in. From c6113a9e447a0358bb462ec82e9ad18215fd9e8a Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 28 Sep 2021 07:53:40 +0100 Subject: [PATCH 12/17] add reference to GMT docs --- pygmt/src/sphdistance.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index e701e307ffb..f6ebd51ae3b 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -31,6 +31,8 @@ def sphdistance(data=None, x=None, y=None, **kwargs): polygons. These polygons are then processed to calculate the nearest distance to each node of the lattice and written to the specified grid. + Full option list at :gmt-docs:`sphdistance.html + {aliases} Parameters From b3ad116790a5d4c1314bea515f5f28ce7552b689 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 28 Sep 2021 08:18:35 +0100 Subject: [PATCH 13/17] update table docstring --- pygmt/src/sphdistance.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index f6ebd51ae3b..2c0dd6d836f 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -26,10 +26,10 @@ def sphdistance(data=None, x=None, y=None, **kwargs): r""" Create Voroni polygons from lat/lon coordinates. - Reads one or more ASCII [or binary] files (or standard - input) containing lon, lat and performs the construction of Voronoi - polygons. These polygons are then processed to calculate the nearest - distance to each node of the lattice and written to the specified grid. + Reads a table containing *lon, lat* columns and performs + the construction of Voronoi polygons. These polygons are + then processed to calculate the nearest distance to each + node of the lattice and written to the specified grid. Full option list at :gmt-docs:`sphdistance.html From a3146888701754e3451de574c9314239cbd9db4c Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 28 Sep 2021 08:19:04 +0100 Subject: [PATCH 14/17] Update pygmt/src/sphdistance.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/sphdistance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 2c0dd6d836f..7d0e4c43753 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -24,7 +24,7 @@ @kwargs_to_strings(I="sequence", R="sequence") def sphdistance(data=None, x=None, y=None, **kwargs): r""" - Create Voroni polygons from lat/lon coordinates. + Create Voronoi polygons from lat/lon coordinates. Reads a table containing *lon, lat* columns and performs the construction of Voronoi polygons. These polygons are From 97108f24000244e70f56b48fc0444b9fc8f0985f Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Tue, 28 Sep 2021 21:42:07 +0100 Subject: [PATCH 15/17] update cache list --- .github/workflows/cache_data.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cache_data.yaml b/.github/workflows/cache_data.yaml index a7d6b56e818..0ea3c2dd510 100644 --- a/.github/workflows/cache_data.yaml +++ b/.github/workflows/cache_data.yaml @@ -3,7 +3,7 @@ name: Cache data on: # Uncomment the 'pull_request' line below to manually re-cache data artifacts - # pull_request: + pull_request: # Schedule runs on 12 noon every Sunday schedule: - cron: '0 12 * * 0' From b836da2469dc376a0b5ebc120a32afcdfe1a472b Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 29 Sep 2021 07:20:48 +0100 Subject: [PATCH 16/17] comment out line for data caching --- .github/workflows/cache_data.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cache_data.yaml b/.github/workflows/cache_data.yaml index 0ea3c2dd510..a7d6b56e818 100644 --- a/.github/workflows/cache_data.yaml +++ b/.github/workflows/cache_data.yaml @@ -3,7 +3,7 @@ name: Cache data on: # Uncomment the 'pull_request' line below to manually re-cache data artifacts - pull_request: + # pull_request: # Schedule runs on 12 noon every Sunday schedule: - cron: '0 12 * * 0' From b59620ce4d1927dd1b395e2c9edc553a422de475 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 29 Sep 2021 07:21:28 +0100 Subject: [PATCH 17/17] Update pygmt/src/sphdistance.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/sphdistance.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index 7d0e4c43753..d2c02ca43e3 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -24,7 +24,8 @@ @kwargs_to_strings(I="sequence", R="sequence") def sphdistance(data=None, x=None, y=None, **kwargs): r""" - Create Voronoi polygons from lat/lon coordinates. + Create Voronoi distance, node, or natural nearest-neighbor grid on a + sphere. Reads a table containing *lon, lat* columns and performs the construction of Voronoi polygons. These polygons are