From 9891e49c99831e4861ce73419bb4e2d81ffffbd1 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 8 Jul 2021 16:17:55 +0100 Subject: [PATCH 01/17] add grdsample.py and import statements --- pygmt/__init__.py | 1 + pygmt/src/__init__.py | 1 + pygmt/src/grdsample.py | 67 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 pygmt/src/grdsample.py diff --git a/pygmt/__init__.py b/pygmt/__init__.py index 972f6474286..08a4bf62b5e 100644 --- a/pygmt/__init__.py +++ b/pygmt/__init__.py @@ -40,6 +40,7 @@ grdgradient, grdinfo, grdlandmask, + grdsample, grdtrack, info, makecpt, diff --git a/pygmt/src/__init__.py b/pygmt/src/__init__.py index f8bae667f02..64cd055f0da 100644 --- a/pygmt/src/__init__.py +++ b/pygmt/src/__init__.py @@ -19,6 +19,7 @@ from pygmt.src.grdimage import grdimage from pygmt.src.grdinfo import grdinfo from pygmt.src.grdlandmask import grdlandmask +from pygmt.src.grdsample import grdsample from pygmt.src.grdtrack import grdtrack from pygmt.src.grdview import grdview from pygmt.src.histogram import histogram diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py new file mode 100644 index 00000000000..8213d54ecd7 --- /dev/null +++ b/pygmt/src/grdsample.py @@ -0,0 +1,67 @@ +""" +grdsample - Resample a grid onto a new lattice +""" + +import xarray as xr +from pygmt.clib import Session +from pygmt.exceptions import GMTInvalidInput +from pygmt.helpers import ( + GMTTempFile, + build_arg_string, + fmt_docstring, + kwargs_to_strings, + use_alias, +) + + +@fmt_docstring +@use_alias( + G="outgrid", + J="projection", + I="increment", + R="region", + T="translate," + V="verbose", +) +@kwargs_to_strings(R="sequence") +def grdsample(grid, **kwargs): + r""" + {aliases} + + Parameters + ---------- + grid : str or xarray.DataArray + The file name of the input grid or the grid loaded as a DataArray. + outgrid : str or None + The name of the output netCDF file with extension .nc to store the grid + in. + {R} + {V} + + Returns + ------- + 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``) + """ + with GMTTempFile(suffix=".nc") as tmpfile: + with Session() as lib: + file_context = lib.virtualfile_from_data(check_kind="raster", data=grid) + with file_context as infile: + if "G" not in kwargs.keys(): # if outgrid is unset, output to tempfile + kwargs.update({"G": tmpfile.name}) + outgrid = kwargs["G"] + arg_str = " ".join([infile, build_arg_string(kwargs)]) + lib.call_module("grdsample", arg_str) + + if outgrid == tmpfile.name: # if user did not set outgrid, return DataArray + with xr.open_dataarray(outgrid) as dataarray: + result = dataarray.load() + _ = result.gmt # load GMTDataArray accessor information + else: + result = None # if user sets an outgrid, return None + + return result From 8b2a7789926854b73872b96eef90ab134a8bfd60 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 8 Jul 2021 16:55:22 +0100 Subject: [PATCH 02/17] add grdsample to index.rst --- doc/api/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/api/index.rst b/doc/api/index.rst index 40ab49ac430..c3d739fc8fb 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -94,6 +94,7 @@ Operations on grids: grdfilter grdlandmask grdgradient + grdsample grdtrack Crossover analysis with x2sys: From 54fde72bafd084bf3dce482f02019e65c4cc4e4a Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 8 Jul 2021 17:05:26 +0100 Subject: [PATCH 03/17] fix comma spacing --- pygmt/src/grdsample.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 8213d54ecd7..aa6e8c3063d 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -20,10 +20,10 @@ J="projection", I="increment", R="region", - T="translate," + T="translate", V="verbose", ) -@kwargs_to_strings(R="sequence") +@kwargs_to_strings(I="sequence", R="sequence") def grdsample(grid, **kwargs): r""" {aliases} From bc60076b2a42f2c73b320416e8bec411a245c85e Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 8 Jul 2021 17:13:43 +0100 Subject: [PATCH 04/17] add grdsample docstring --- pygmt/src/grdsample.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index aa6e8c3063d..93d5b14401d 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -22,10 +22,25 @@ R="region", T="translate", V="verbose", + n="interpolation", + r="registration", ) @kwargs_to_strings(I="sequence", R="sequence") def grdsample(grid, **kwargs): r""" + This reads a grid file and interpolates it to create a new grid + file. It can change the registration with ``translate`` or + ``registration``, change the grid-spacing or number of nodes with + ``increment``, and set a new sub-region using ``region``. A bicubic + [Default], bilinear, B-spline or nearest-neighbor interpolation is set + with ``interpolation``. + + When ``region`` is omitted, the output grid will cover the same region as + the input grid. When ``increment`` is omitted, the grid spacing of the + output grid will be the same as the input grid. Either ``registration`` or + ``translate`` can be used to change the grid registration. When omitted, + the output grid will have the same registration as the input grid. + {aliases} Parameters From 33a9960494c35ba11b22022974e3e2b654aafb93 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 8 Jul 2021 17:21:53 +0100 Subject: [PATCH 05/17] add parameter docstrings --- pygmt/src/grdsample.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 93d5b14401d..840a959678b 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -50,7 +50,34 @@ def grdsample(grid, **kwargs): outgrid : str or None The name of the output netCDF file with extension .nc to store the grid in. + {I} {R} + translate : bool + Translate between grid and pixel registration; if the input is + grid-registered, the output will be pixel-registered and vice-versa. + interpolation : str + [**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**][**+t**\ *threshold*]. + Select interpolation mode for grids. + + - **b** to use B-spline smoothing. + - **c** to use bicubic interpolation. + - **l** to use bilinear interpolation. + - **n** to use nearest-neighbor value (for example to plot categorical data). + + The following modifiers are supported: + + - **+a** to switch off antialiasing (where supported) [default uses antialiasing]. + - **+b** to override boundary conditions used, by appending *g* for geographic, *p* for periodic, or *n* for + natural boundary conditions. For the latter two you may append **x** or **y** to specify just one direction, otherwise + both are assumed. + - **+c** to clip the interpolated grid to input z-min/z-max [default may exceed limits]. + - **+t** to control how close to nodes with NaNs the interpolation will go based on *threshold*. A *threshold* of 1.0 + requires all (4 or 16) nodes involved in interpolation to be non-NaN. For example, 0.5 will interpolate about half + way from a non-NaN value and 0.1 will go about 90% of the way [default is 0.5]. + registration : str + [**g**\ |\ **p**\ ]. + Set registrationg to **g**\ ridline or **p**\ ixel. + {V} Returns From 5d0aeb5aa6d28eef29825ae8ff74c6a0af2bfe28 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 8 Jul 2021 17:24:22 +0100 Subject: [PATCH 06/17] formatting fix --- pygmt/src/grdsample.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 840a959678b..173474defd6 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -56,24 +56,31 @@ def grdsample(grid, **kwargs): Translate between grid and pixel registration; if the input is grid-registered, the output will be pixel-registered and vice-versa. interpolation : str - [**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**][**+t**\ *threshold*]. + [**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**] + [**+t**\ *threshold*]. Select interpolation mode for grids. - **b** to use B-spline smoothing. - **c** to use bicubic interpolation. - **l** to use bilinear interpolation. - - **n** to use nearest-neighbor value (for example to plot categorical data). + - **n** to use nearest-neighbor value (for example to plot + categorical data). The following modifiers are supported: - - **+a** to switch off antialiasing (where supported) [default uses antialiasing]. - - **+b** to override boundary conditions used, by appending *g* for geographic, *p* for periodic, or *n* for - natural boundary conditions. For the latter two you may append **x** or **y** to specify just one direction, otherwise - both are assumed. - - **+c** to clip the interpolated grid to input z-min/z-max [default may exceed limits]. - - **+t** to control how close to nodes with NaNs the interpolation will go based on *threshold*. A *threshold* of 1.0 - requires all (4 or 16) nodes involved in interpolation to be non-NaN. For example, 0.5 will interpolate about half - way from a non-NaN value and 0.1 will go about 90% of the way [default is 0.5]. + - **+a** to switch off antialiasing (where supported) [default uses + antialiasing]. + - **+b** to override boundary conditions used, by appending *g* for + geographic, *p* for periodic, or *n* for natural boundary conditions. + For the latter two you may append **x** or **y** to specify just one + direction, otherwise both are assumed. + - **+c** to clip the interpolated grid to input z-min/z-max + [default may exceed limits]. + - **+t** to control how close to nodes with NaNs the interpolation + will go based on *threshold*. A *threshold* of 1.0 requires all + (4 or 16) nodes involved in interpolation to be non-NaN. For example, + 0.5 will interpolate about half way from a non-NaN value and 0.1 will + go about 90% of the way [default is 0.5]. registration : str [**g**\ |\ **p**\ ]. Set registrationg to **g**\ ridline or **p**\ ixel. From 78869316f286406772533a226bc84fafd7afc5bb Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 8 Jul 2021 17:47:57 +0100 Subject: [PATCH 07/17] add test_grdsample.py --- pygmt/tests/test_grdsample.py | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 pygmt/tests/test_grdsample.py diff --git a/pygmt/tests/test_grdsample.py b/pygmt/tests/test_grdsample.py new file mode 100644 index 00000000000..804d330be3a --- /dev/null +++ b/pygmt/tests/test_grdsample.py @@ -0,0 +1,45 @@ +""" +Tests for grdsample. +""" +import os + +import numpy.testing as npt +import pytest +from pygmt import grdinfo, grdsample +from pygmt.datasets import load_earth_relief +from pygmt.helpers import GMTTempFile + + +@pytest.fixture(scope="module", name="grid") +def fixture_grid(): + """ + Load the grid data from the sample earth_relief file. + """ + return load_earth_relief( + resolution="01d", region=[-5, 5, -5, 5], registration="pixel" + ) + + +def test_grdsample_file_out(grid): + """ + grdsample with an outgrid set and the increment is changed. + """ + with GMTTempFile(suffix=".nc") as tmpfile: + result = grdsample(grid=grid, outgrid=tmpfile.name, increment=[1, 2.5]) + assert result is None # return value is None + assert os.path.exists(path=tmpfile.name) # check that outgrid exists + result = grdinfo(tmpfile.name, per_column=True).strip().split() + print(result) + assert float(result[6]) == 1 # x-increment + assert float(result[7]) == 2.5 # y-increment + + +def test_grdsample_no_outgrid(grid): + """ + Test grdsample with no set outgrid and applying registration changes. + """ + assert grid.gmt.registration == 1 # Pixel registration + translated_grid = grdsample(grid=grid, translate=True) + assert translated_grid.gmt.registration == 0 # Gridline registration + registration_grid = grdsample(grid=translated_grid, registration="p") + assert registration_grid.gmt.registration == 1 # Pixel registration From 22aafe59d3079bb5ba6ec3f81e2a2516799a2092 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Thu, 8 Jul 2021 18:03:17 +0100 Subject: [PATCH 08/17] remove unused imports --- pygmt/src/grdsample.py | 1 - pygmt/tests/test_grdsample.py | 1 - 2 files changed, 2 deletions(-) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 173474defd6..6a8169aaa93 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -4,7 +4,6 @@ import xarray as xr from pygmt.clib import Session -from pygmt.exceptions import GMTInvalidInput from pygmt.helpers import ( GMTTempFile, build_arg_string, diff --git a/pygmt/tests/test_grdsample.py b/pygmt/tests/test_grdsample.py index 804d330be3a..c95898ced7b 100644 --- a/pygmt/tests/test_grdsample.py +++ b/pygmt/tests/test_grdsample.py @@ -3,7 +3,6 @@ """ import os -import numpy.testing as npt import pytest from pygmt import grdinfo, grdsample from pygmt.datasets import load_earth_relief From 54f2ada42e0bea67d696485bb37cc3ff89ebfd6c Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 12 Jul 2021 17:41:54 +0100 Subject: [PATCH 09/17] add single line description for module in docstring --- pygmt/src/grdsample.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 6a8169aaa93..c409984fd56 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -27,6 +27,8 @@ @kwargs_to_strings(I="sequence", R="sequence") def grdsample(grid, **kwargs): r""" + Change the registration, spacing, or nodes in a grid file. + This reads a grid file and interpolates it to create a new grid file. It can change the registration with ``translate`` or ``registration``, change the grid-spacing or number of nodes with From 9f8c0c7a0bd1fce18155ffaeffaf0c7923995007 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 14 Jul 2021 16:01:09 +0100 Subject: [PATCH 10/17] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/grdsample.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index c409984fd56..c7e2002e56e 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -21,8 +21,10 @@ R="region", T="translate", V="verbose", - n="interpolation", + f="coltypes", r="registration", + n="interpolation", + x="cores", ) @kwargs_to_strings(I="sequence", R="sequence") def grdsample(grid, **kwargs): @@ -84,9 +86,11 @@ def grdsample(grid, **kwargs): go about 90% of the way [default is 0.5]. registration : str [**g**\ |\ **p**\ ]. - Set registrationg to **g**\ ridline or **p**\ ixel. + Set registration to **g**\ ridline or **p**\ ixel. {V} + {f} + {x} Returns ------- From 593d712649c84b8215fe853beb102ac588f49031 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 14 Jul 2021 16:04:07 +0100 Subject: [PATCH 11/17] add bool option to registration parameter --- pygmt/src/grdsample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index c7e2002e56e..2e751cd3437 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -84,7 +84,7 @@ def grdsample(grid, **kwargs): (4 or 16) nodes involved in interpolation to be non-NaN. For example, 0.5 will interpolate about half way from a non-NaN value and 0.1 will go about 90% of the way [default is 0.5]. - registration : str + registration : str or bool [**g**\ |\ **p**\ ]. Set registration to **g**\ ridline or **p**\ ixel. From 2ff155048e9d9e3e4cfbde888dd8672b24b7fc7f Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Fri, 16 Jul 2021 17:37:24 +0100 Subject: [PATCH 12/17] move "interpolation" to COMMON_OPTIONS in decorators.py --- pygmt/helpers/decorators.py | 35 ++++++++++++++++++++++++++--------- pygmt/src/grdsample.py | 27 +-------------------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index 04df0ca4cfb..f7ad89840dc 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -164,15 +164,32 @@ (:gmt-term:`PROJ_AUX_LATITUDE`). Geodesic distance calculations is also controlled by method (:gmt-term:`PROJ_GEODESIC`).""", "n": r""" - interpolation : str - [**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**][**+t**\ *threshold*]. - Select interpolation mode for grids. You can select the type of - spline used: - - - **b** for B-spline - - **c** for bicubic [Default] - - **l** for bilinear - - **n** for nearest-neighbor""", + interpolation : str + [**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**] + [**+t**\ *threshold*]. + Select interpolation mode for grids. + + - **b** to use B-spline smoothing. + - **c** to use bicubic interpolation. + - **l** to use bilinear interpolation. + - **n** to use nearest-neighbor value (for example to plot + categorical data). + + The following modifiers are supported: + + - **+a** to switch off antialiasing (where supported) [default uses + antialiasing]. + - **+b** to override boundary conditions used, by appending *g* for + geographic, *p* for periodic, or *n* for natural boundary conditions. + For the latter two you may append **x** or **y** to specify just one + direction, otherwise both are assumed. + - **+c** to clip the interpolated grid to input z-min/z-max + [default may exceed limits]. + - **+t** to control how close to nodes with NaNs the interpolation + will go based on *threshold*. A *threshold* of 1.0 requires all + (4 or 16) nodes involved in interpolation to be non-NaN. For example, + 0.5 will interpolate about half way from a non-NaN value and 0.1 will + go about 90% of the way [default is 0.5].""", "p": r""" perspective : list or str [**x**\|\ **y**\|\ **z**]\ *azim*\[/*elev*\[/*zlevel*]]\ diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 2e751cd3437..da71f1f31e9 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -58,32 +58,7 @@ def grdsample(grid, **kwargs): translate : bool Translate between grid and pixel registration; if the input is grid-registered, the output will be pixel-registered and vice-versa. - interpolation : str - [**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**] - [**+t**\ *threshold*]. - Select interpolation mode for grids. - - - **b** to use B-spline smoothing. - - **c** to use bicubic interpolation. - - **l** to use bilinear interpolation. - - **n** to use nearest-neighbor value (for example to plot - categorical data). - - The following modifiers are supported: - - - **+a** to switch off antialiasing (where supported) [default uses - antialiasing]. - - **+b** to override boundary conditions used, by appending *g* for - geographic, *p* for periodic, or *n* for natural boundary conditions. - For the latter two you may append **x** or **y** to specify just one - direction, otherwise both are assumed. - - **+c** to clip the interpolated grid to input z-min/z-max - [default may exceed limits]. - - **+t** to control how close to nodes with NaNs the interpolation - will go based on *threshold*. A *threshold* of 1.0 requires all - (4 or 16) nodes involved in interpolation to be non-NaN. For example, - 0.5 will interpolate about half way from a non-NaN value and 0.1 will - go about 90% of the way [default is 0.5]. + {n} registration : str or bool [**g**\ |\ **p**\ ]. Set registration to **g**\ ridline or **p**\ ixel. From ad609c3a48c6ea8ea5d926913c280c973df643cb Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sat, 17 Jul 2021 06:57:50 +0100 Subject: [PATCH 13/17] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/helpers/decorators.py | 52 ++++++++++++++++++------------------- pygmt/src/grdsample.py | 3 +-- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index f7ad89840dc..d072a6e73ad 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -164,32 +164,32 @@ (:gmt-term:`PROJ_AUX_LATITUDE`). Geodesic distance calculations is also controlled by method (:gmt-term:`PROJ_GEODESIC`).""", "n": r""" - interpolation : str - [**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**] - [**+t**\ *threshold*]. - Select interpolation mode for grids. - - - **b** to use B-spline smoothing. - - **c** to use bicubic interpolation. - - **l** to use bilinear interpolation. - - **n** to use nearest-neighbor value (for example to plot - categorical data). - - The following modifiers are supported: - - - **+a** to switch off antialiasing (where supported) [default uses - antialiasing]. - - **+b** to override boundary conditions used, by appending *g* for - geographic, *p* for periodic, or *n* for natural boundary conditions. - For the latter two you may append **x** or **y** to specify just one - direction, otherwise both are assumed. - - **+c** to clip the interpolated grid to input z-min/z-max - [default may exceed limits]. - - **+t** to control how close to nodes with NaNs the interpolation - will go based on *threshold*. A *threshold* of 1.0 requires all - (4 or 16) nodes involved in interpolation to be non-NaN. For example, - 0.5 will interpolate about half way from a non-NaN value and 0.1 will - go about 90% of the way [default is 0.5].""", + interpolation : str + [**b**\|\ **c**\|\ **l**\|\ **n**][**+a**][**+b**\ *BC*][**+c**]\ + [**+t**\ *threshold*]. + Select interpolation mode for grids. + + - **b** to use B-spline smoothing. + - **c** to use bicubic interpolation. + - **l** to use bilinear interpolation. + - **n** to use nearest-neighbor value (for example to plot + categorical data). + + The following modifiers are supported: + + - **+a** to switch off antialiasing (where supported) [default uses + antialiasing]. + - **+b** to override boundary conditions used, by appending *g* for + geographic, *p* for periodic, or *n* for natural boundary + conditions. For the latter two you may append **x** or **y** to + specify just one direction, otherwise both are assumed. + - **+c** to clip the interpolated grid to input z-min/z-max + [default may exceed limits]. + - **+t** to control how close to nodes with NaNs the interpolation + will go based on *threshold*. A *threshold* of 1.0 requires all + (4 or 16) nodes involved in interpolation to be non-NaN. For + example, 0.5 will interpolate about half way from a non-NaN value + and 0.1 will go about 90% of the way [default is 0.5].""", "p": r""" perspective : list or str [**x**\|\ **y**\|\ **z**]\ *azim*\[/*elev*\[/*zlevel*]]\ diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index da71f1f31e9..b1b4393e6b9 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -58,13 +58,12 @@ def grdsample(grid, **kwargs): translate : bool Translate between grid and pixel registration; if the input is grid-registered, the output will be pixel-registered and vice-versa. - {n} registration : str or bool [**g**\ |\ **p**\ ]. Set registration to **g**\ ridline or **p**\ ixel. - {V} {f} + {n} {x} Returns From 9636ac1b99a8cbd527b55b9d0ab7b01baa01f306 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Wed, 4 Aug 2021 19:24:03 +0100 Subject: [PATCH 14/17] Apply suggestions from code review Co-authored-by: Michael Grund <23025878+michaelgrund@users.noreply.github.com> --- pygmt/helpers/decorators.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pygmt/helpers/decorators.py b/pygmt/helpers/decorators.py index f95efb4172f..c15f882836f 100644 --- a/pygmt/helpers/decorators.py +++ b/pygmt/helpers/decorators.py @@ -181,19 +181,19 @@ The following modifiers are supported: - - **+a** to switch off antialiasing (where supported) [default uses + - **+a** to switch off antialiasing (where supported) [Default uses antialiasing]. - **+b** to override boundary conditions used, by appending *g* for geographic, *p* for periodic, or *n* for natural boundary conditions. For the latter two you may append **x** or **y** to specify just one direction, otherwise both are assumed. - **+c** to clip the interpolated grid to input z-min/z-max - [default may exceed limits]. + [Default may exceed limits]. - **+t** to control how close to nodes with NaNs the interpolation will go based on *threshold*. A *threshold* of 1.0 requires all (4 or 16) nodes involved in interpolation to be non-NaN. For example, 0.5 will interpolate about half way from a non-NaN value - and 0.1 will go about 90% of the way [default is 0.5].""", + and 0.1 will go about 90% of the way [Default is 0.5].""", "p": r""" perspective : list or str [**x**\|\ **y**\|\ **z**]\ *azim*\[/*elev*\[/*zlevel*]]\ From ac5fee4a99d5b489867f2b6e362c9a0d3ac411e5 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 8 Aug 2021 09:11:47 +0100 Subject: [PATCH 15/17] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/src/grdsample.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index b1b4393e6b9..90c7f722727 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -22,8 +22,8 @@ T="translate", V="verbose", f="coltypes", - r="registration", n="interpolation", + r="registration", x="cores", ) @kwargs_to_strings(I="sequence", R="sequence") From 4727aae04a918ba1a8c6966358b0818da2392abb Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Sun, 8 Aug 2021 20:49:40 +0100 Subject: [PATCH 16/17] Apply suggestions from code review Co-authored-by: Dongdong Tian --- pygmt/tests/test_grdsample.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pygmt/tests/test_grdsample.py b/pygmt/tests/test_grdsample.py index c95898ced7b..84f1f4ccf77 100644 --- a/pygmt/tests/test_grdsample.py +++ b/pygmt/tests/test_grdsample.py @@ -24,13 +24,12 @@ def test_grdsample_file_out(grid): grdsample with an outgrid set and the increment is changed. """ with GMTTempFile(suffix=".nc") as tmpfile: - result = grdsample(grid=grid, outgrid=tmpfile.name, increment=[1, 2.5]) + result = grdsample(grid=grid, outgrid=tmpfile.name, increment=[1, 0.5]) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = grdinfo(tmpfile.name, per_column=True).strip().split() - print(result) assert float(result[6]) == 1 # x-increment - assert float(result[7]) == 2.5 # y-increment + assert float(result[7]) == 0.5 # y-increment def test_grdsample_no_outgrid(grid): From 09a43de88090ac5eef6018fa66e10cc416df53e2 Mon Sep 17 00:00:00 2001 From: Will Schlitzer Date: Mon, 9 Aug 2021 08:02:55 +0100 Subject: [PATCH 17/17] Apply suggestions from code review --- pygmt/src/grdsample.py | 6 +++--- pygmt/tests/test_grdsample.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pygmt/src/grdsample.py b/pygmt/src/grdsample.py index 90c7f722727..b1c807ccf94 100644 --- a/pygmt/src/grdsample.py +++ b/pygmt/src/grdsample.py @@ -17,7 +17,7 @@ @use_alias( G="outgrid", J="projection", - I="increment", + I="spacing", R="region", T="translate", V="verbose", @@ -34,12 +34,12 @@ def grdsample(grid, **kwargs): This reads a grid file and interpolates it to create a new grid file. It can change the registration with ``translate`` or ``registration``, change the grid-spacing or number of nodes with - ``increment``, and set a new sub-region using ``region``. A bicubic + ``spacing``, and set a new sub-region using ``region``. A bicubic [Default], bilinear, B-spline or nearest-neighbor interpolation is set with ``interpolation``. When ``region`` is omitted, the output grid will cover the same region as - the input grid. When ``increment`` is omitted, the grid spacing of the + the input grid. When ``spacing`` is omitted, the grid spacing of the output grid will be the same as the input grid. Either ``registration`` or ``translate`` can be used to change the grid registration. When omitted, the output grid will have the same registration as the input grid. diff --git a/pygmt/tests/test_grdsample.py b/pygmt/tests/test_grdsample.py index 84f1f4ccf77..5222e7cf987 100644 --- a/pygmt/tests/test_grdsample.py +++ b/pygmt/tests/test_grdsample.py @@ -21,10 +21,10 @@ def fixture_grid(): def test_grdsample_file_out(grid): """ - grdsample with an outgrid set and the increment is changed. + grdsample with an outgrid set and the spacing is changed. """ with GMTTempFile(suffix=".nc") as tmpfile: - result = grdsample(grid=grid, outgrid=tmpfile.name, increment=[1, 0.5]) + result = grdsample(grid=grid, outgrid=tmpfile.name, spacing=[1, 0.5]) assert result is None # return value is None assert os.path.exists(path=tmpfile.name) # check that outgrid exists result = grdinfo(tmpfile.name, per_column=True).strip().split()