pygmt.GMTDataArrayAccessor.fill
- GMTDataArrayAccessor.fill(outgrid=None, constantfill=None, gridfill=None, neighborfill=None, splinefill=None, inquire=False, hole=None, mode=None, verbose=False, **kwargs)
Interpolate across holes in a grid.
Read a grid that presumably has unfilled holes that the user wants to fill in some fashion. Holes are identified by NaN values but this criteria can be changed via the
holeparameter. There are several different algorithms that can be used to replace the hole values. If no holes are found the original unchanged grid is returned.Full GMT docs at https://docs.generic-mapping-tools.org/6.5/grdfill.html.
Aliases:
R = region
f = coltypes
Ac = constantfill
Ag = gridfill
An = neighborfill
As = splinefill
L = inquire
N = hole
V = verbose
- Parameters:
grid (
str|PathLike|DataArray) –Name of the input grid file or the grid loaded as a
xarray.DataArrayobject.For reading a specific grid file format or applying basic data operations, see https://docs.generic-mapping-tools.org/6.5/gmt.html#grd-inout-full for the available modifiers.
outgrid (
str|PathLike|None, default:None) – Name of the output netCDF grid file. If not specified, will return anxarray.DataArrayobject. For writing a specific grid file format or applying basic data operations to the output grid, see https://docs.generic-mapping-tools.org/6.5/gmt.html#grd-inout-full for the available modifiers.constantfill (
float|None, default:None) – Fill the holes with a constant value. Specify the constant value to use.gridfill (
str|PathLike|DataArray|None, default:None) – Fill the holes with values sampled from another (possibly coarser) grid. Specify the grid (a file name or anxarray.DataArray) to use for the fill.neighborfill (
float|bool|None, default:None) – Fill the holes with the nearest neighbor. Specify the search radius in pixels. If set toTrue, the default search radius will be used (\(r^2 = \sqrt{n^2 + m^2}\), where (n,m) are the node dimensions of the grid).splinefill (
float|bool|None, default:None) – Fill the holes with a bicubic spline. Specify the tension value to use. If set toTrue, no tension will be used.hole (
float|None, default:None) – Set the node value used to identify a point as a member of a hole [Default is NaN].inquire (
bool, default:False) – Output the bounds of each hole. The bounds are returned as a 2-D numpy array in the form of (west, east, south, north). No grid fill takes place andoutgridis ignored.mode (
str|None, default:None) –Specify the hole-filling algorithm to use. Choose from c for constant fill and append the constant value, n for nearest neighbor (and optionally append a search radius in pixels [default radius is \(r^2 = \sqrt{ X^2 + Y^2 }\), where (X,Y) are the node dimensions of the grid]), or s for bicubic spline (optionally append a tension parameter [Default is no tension]).
Deprecated since version 0.15.0: Use
constantfill,gridfill,neighborfill, orsplinefillinstead. The parameter will be removed in v0.19.0.region (str or list) – xmin/xmax/ymin/ymax[+r][+uunit]. Specify the region of interest.
coltypes (str) – [i|o]colinfo. Specify data types of input and/or output columns (time or geographical data). Full documentation is at https://docs.generic-mapping-tools.org/6.5/gmt.html#f-full.
verbose (bool or str) – Select verbosity level [Full usage].
- Return type:
- Returns:
ret – If
inquireisTrue, return the bounds of each hole as a 2-D numpy array. Otherwise, the return type depends on whether theoutgridparameter is set:xarray.DataArrayifoutgridis not setNoneifoutgridis set (grid output will be stored in the file set byoutgrid)
Example
Fill holes in a bathymetric grid with a constant value of 20.
>>> import pygmt >>> # Load a bathymetric grid with missing data >>> earth_relief_holes = pygmt.datasets.load_sample_data(name="earth_relief_holes") >>> # Fill the holes with a constant value of 20 >>> filled_grid = pygmt.grdfill(grid=earth_relief_holes, constantfill=20)
Inquire the bounds of each hole.
>>> pygmt.grdfill(grid=earth_relief_holes, inquire=True) array([[1.83333333, 6.16666667, 3.83333333, 8.16666667], [6.16666667, 7.83333333, 0.5 , 2.5 ]])