From 223f84fb39ffd4af6cec5d490692127cd64afc10 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 2 Feb 2022 16:20:55 +0000 Subject: [PATCH 01/10] add inline example for xyz2grd.py --- pygmt/src/xyz2grd.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 634585a0e75..4f5ad884838 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -131,6 +131,19 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): - :class:`xarray.DataArray`: if ``outgrid`` is not set - None if ``outgrid`` is set (grid output will be stored in file set by ``outgrid``) + + Example + ------- + >>> import pygmt # doctest: +SKIP + >>> # Load a sample bathymetry file + >>> sample_bathymetry = ( + ... pygmt.datasets.load_sample_bathymetry() + ... ) # doctest: +SKIP + >>> # Create a new grid from the xyz input, set the x-range to 245-255 and + >>> # the y-range to 20-30, and the spacing to 5 degrees + >>> new_grid = pygmt.xyz2grd( + ... data=ship_data, spacing=5, region=[245, 255, 20, 30] + ... ) # doctest: +SKIP """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: From 39237568ff3b84c9149870ac44b057ff6b9d1bbb Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 14 Feb 2022 16:43:50 +0000 Subject: [PATCH 02/10] Apply suggestions from code review Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com> --- pygmt/src/xyz2grd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 4f5ad884838..1ec43aad260 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -137,12 +137,12 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): >>> import pygmt # doctest: +SKIP >>> # Load a sample bathymetry file >>> sample_bathymetry = ( - ... pygmt.datasets.load_sample_bathymetry() + ... pygmt.datasets.load_sample_data(name="bathymetry") ... ) # doctest: +SKIP >>> # Create a new grid from the xyz input, set the x-range to 245-255 and >>> # the y-range to 20-30, and the spacing to 5 degrees >>> new_grid = pygmt.xyz2grd( - ... data=ship_data, spacing=5, region=[245, 255, 20, 30] + ... data=sample_bathymetry, spacing=5, region=[245, 255, 20, 30] ... ) # doctest: +SKIP """ with GMTTempFile(suffix=".nc") as tmpfile: From 4fc7997a81f8f6f915357616305e4b7cd78b6e5d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 14 Feb 2022 16:45:46 +0000 Subject: [PATCH 03/10] run make format --- pygmt/src/xyz2grd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 1ec43aad260..2dd01a7a5c7 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -136,8 +136,8 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): ------- >>> import pygmt # doctest: +SKIP >>> # Load a sample bathymetry file - >>> sample_bathymetry = ( - ... pygmt.datasets.load_sample_data(name="bathymetry") + >>> sample_bathymetry = pygmt.datasets.load_sample_data( + ... name="bathymetry" ... ) # doctest: +SKIP >>> # Create a new grid from the xyz input, set the x-range to 245-255 and >>> # the y-range to 20-30, and the spacing to 5 degrees From 63da308609863bc5e9748806172b82433cc3e92d Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 11 Mar 2022 09:33:55 +0000 Subject: [PATCH 04/10] update inline example --- pygmt/src/xyz2grd.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 2dd01a7a5c7..b4b06de5964 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -11,6 +11,7 @@ ) from pygmt.io import load_dataarray +__doctest_skip__ = ["xyz2grd"] @fmt_docstring @use_alias( @@ -134,16 +135,14 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): Example ------- - >>> import pygmt # doctest: +SKIP - >>> # Load a sample bathymetry file - >>> sample_bathymetry = pygmt.datasets.load_sample_data( - ... name="bathymetry" - ... ) # doctest: +SKIP - >>> # Create a new grid from the xyz input, set the x-range to 245-255 and - >>> # the y-range to 20-30, and the spacing to 5 degrees - >>> new_grid = pygmt.xyz2grd( - ... data=sample_bathymetry, spacing=5, region=[245, 255, 20, 30] - ... ) # doctest: +SKIP + >>> import numpy as np + >>> import pygmt + >>> # prepare input arrays + >>> x, y = np.meshgrid([0, 1, 2, 3], [10.5, 11.0, 11.5, 12.0, 12.5]) + >>> z = x**2 + y**2 + >>> xx, yy, zz = x.flatten(), y.flatten(), z.flatten() + + >>> grid = pygmt.xyz2grd(x=xx, y=yy, z=zz, spacing=(1.0, 0.5)) """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: From f041309f7f8dd9457c24acd5bc1ca0ff69633529 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 11 Mar 2022 21:55:29 +0800 Subject: [PATCH 05/10] Fix linting issue --- pygmt/src/xyz2grd.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index b4b06de5964..37e435e7092 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -13,6 +13,7 @@ __doctest_skip__ = ["xyz2grd"] + @fmt_docstring @use_alias( A="duplicate", From 4454b65a16e1f8e879968328d94f0a27acebdf9a Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 11 Mar 2022 21:59:56 +0800 Subject: [PATCH 06/10] Apply suggestions from code review --- pygmt/src/xyz2grd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 37e435e7092..e4c5fd4ab49 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -138,11 +138,11 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): ------- >>> import numpy as np >>> import pygmt - >>> # prepare input arrays + >>> # generate a grid for z=x**2+y**2, with an x-range of 0 to 3, + >>> # and a range of 10.5 to 12.5. The x- and y-spacing are 1.0 and 0.5. >>> x, y = np.meshgrid([0, 1, 2, 3], [10.5, 11.0, 11.5, 12.0, 12.5]) >>> z = x**2 + y**2 >>> xx, yy, zz = x.flatten(), y.flatten(), z.flatten() - >>> grid = pygmt.xyz2grd(x=xx, y=yy, z=zz, spacing=(1.0, 0.5)) """ with GMTTempFile(suffix=".nc") as tmpfile: From 3522401b8b1720a4a376fa96d5e35b57645c3523 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Fri, 11 Mar 2022 22:00:59 +0800 Subject: [PATCH 07/10] Fix formatting --- pygmt/src/xyz2grd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index e4c5fd4ab49..89f8b114ad1 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -138,7 +138,7 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): ------- >>> import numpy as np >>> import pygmt - >>> # generate a grid for z=x**2+y**2, with an x-range of 0 to 3, + >>> # generate a grid for z=x**2+y**2, with an x-range of 0 to 3, >>> # and a range of 10.5 to 12.5. The x- and y-spacing are 1.0 and 0.5. >>> x, y = np.meshgrid([0, 1, 2, 3], [10.5, 11.0, 11.5, 12.0, 12.5]) >>> z = x**2 + y**2 From 21ee0990b6b2d2ad4e76caa000a859e50947fe39 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 12 Mar 2022 08:27:24 +0000 Subject: [PATCH 08/10] add I to sequence in kwargs_to_strings, add region for xyz2grd docstring inline example --- pygmt/src/xyz2grd.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 89f8b114ad1..fa2b3411ccb 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -32,7 +32,7 @@ r="registration", w="wrap", ) -@kwargs_to_strings(R="sequence") +@kwargs_to_strings(I="sequence", R="sequence") def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): r""" Create a grid file from table data. @@ -143,7 +143,9 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): >>> x, y = np.meshgrid([0, 1, 2, 3], [10.5, 11.0, 11.5, 12.0, 12.5]) >>> z = x**2 + y**2 >>> xx, yy, zz = x.flatten(), y.flatten(), z.flatten() - >>> grid = pygmt.xyz2grd(x=xx, y=yy, z=zz, spacing=(1.0, 0.5)) + >>> grid = pygmt.xyz2grd( + ... x=xx, y=yy, z=zz, spacing=(1.0, 0.5), region=[0, 3, 10, 13] + ... ) """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: From 03877b9839a4fc4fea5351033dc7193f42a47e21 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 12 Mar 2022 08:30:33 +0000 Subject: [PATCH 09/10] fix use of GMT alias in PyGMT docstring --- pygmt/src/xyz2grd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index fa2b3411ccb..67230781023 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -110,7 +110,7 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): - **f** 4-byte floating point single precision - **d** 8-byte floating point double precision - Default format is scanline orientation of ASCII numbers: **-ZTLa**. + [Default format is scanline orientation of ASCII numbers: **La**]. The difference between **A** and **a** is that the latter can decode both *date*\ **T**\ *clock* and *ddd:mm:ss[.xx]* formats but expects each input record to have a single value, while the former can handle From 7209ecb5c049eee8871df785c1dedbc5d013ef37 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 14 Mar 2022 10:41:35 +0000 Subject: [PATCH 10/10] Update pygmt/src/xyz2grd.py Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/xyz2grd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 0396cbca655..7deb42778ab 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -140,7 +140,7 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs): >>> import numpy as np >>> import pygmt >>> # generate a grid for z=x**2+y**2, with an x-range of 0 to 3, - >>> # and a range of 10.5 to 12.5. The x- and y-spacing are 1.0 and 0.5. + >>> # and a y-range of 10.5 to 12.5. The x- and y-spacing are 1.0 and 0.5. >>> x, y = np.meshgrid([0, 1, 2, 3], [10.5, 11.0, 11.5, 12.0, 12.5]) >>> z = x**2 + y**2 >>> xx, yy, zz = x.flatten(), y.flatten(), z.flatten()