Skip to content

Commit

Permalink
Update grdfill parameters for GMT 6.2.0 (#1283)
Browse files Browse the repository at this point in the history
Add an additional `verbose` (-V) parameter to the `grdfill` module,
include the new mode='s' option, and set 'mode' and 'L' as required
parameters.

* fix top docstring
* make A/L required arguments
* add s option in docs for mode in grdfill

Co-authored-by: Dongdong Tian <[email protected]>
Co-authored-by: Meghan Jones <[email protected]>
Co-authored-by: Wei Ji <[email protected]>
  • Loading branch information
4 people committed Jun 16, 2021
1 parent e3510ad commit 623fe21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pygmt/src/grdfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import xarray as xr
from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
GMTTempFile,
build_arg_string,
Expand All @@ -18,6 +19,7 @@
A="mode",
G="outgrid",
R="region",
V="verbose",
)
@kwargs_to_strings(R="sequence")
def grdfill(grid, **kwargs):
Expand Down Expand Up @@ -45,8 +47,12 @@ def grdfill(grid, **kwargs):
constant fill and append the constant value, **n** for nearest
neighbor (and optionally append a search radius in
pixels [default radius is :math:`r^2 = \sqrt{{ X^2 + Y^2 }}`,
where (*X,Y*) are the node dimensions of the grid]).
where (*X,Y*) are the node dimensions of the grid]), or
**s** for bicubic spline (optionally append a *tension*
parameter [Default is no tension]).
{R}
{V}
Returns
-------
Expand All @@ -57,6 +63,8 @@ def grdfill(grid, **kwargs):
- None if ``outgrid`` is set (grid output will be stored in file set by
``outgrid``)
"""
if "A" not in kwargs.keys() and "L" not in kwargs.keys():
raise GMTInvalidInput("At least parameter 'mode' or 'L' must be specified.")
with GMTTempFile(suffix=".nc") as tmpfile:
with Session() as lib:
file_context = lib.virtualfile_from_data(check_kind="raster", data=grid)
Expand Down
11 changes: 10 additions & 1 deletion pygmt/tests/test_grdfill.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Tests for grdclip.
Tests for grdfill.
"""
import os

Expand All @@ -8,6 +8,7 @@
import xarray as xr
from pygmt import grdfill, grdinfo
from pygmt.datasets import load_earth_relief
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import GMTTempFile


Expand Down Expand Up @@ -47,3 +48,11 @@ def test_grdfill_file_out(grid):
assert os.path.exists(path=tmpfile.name) # check that outgrid exists
result = grdinfo(tmpfile.name, per_column=True).strip()
assert result == "-5 5 -5 5 -5130.5 inf 1 1 10 10 1 1"


def test_grdfill_required_args(grid):
"""
Test that grdfill fails without arguments for `mode` and `L`.
"""
with pytest.raises(GMTInvalidInput):
grdfill(grid=grid)

0 comments on commit 623fe21

Please sign in to comment.