pygmt.grdfill

pygmt.grdfill(grid, outgrid=None, constantfill=None, gridfill=None, neighborfill=None, splinefill=None, **kwargs)[source]

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 hole parameter. 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 option list at https://docs.generic-mapping-tools.org/6.5/grdfill.html.

Aliases:

  • A = mode

  • N = hole

  • R = region

  • V = verbose

  • f = coltypes

Parameters:
  • grid (str or xarray.DataArray) –

    Name of the input grid file or the grid loaded as a xarray.DataArray object.

    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 | None, default: None) – Name of the output netCDF grid file. If not specified, will return an xarray.DataArray object. 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 | DataArray | None, default: None) – Fill the holes with values sampled from another (possibly coarser) grid. Specify the grid (a file name or an xarray.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 to True, 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 to True, no tension will be used.

  • hole (float) – Set the node value used to identify a point as a member of a hole [Default is NaN].

  • mode (str) –

    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, or splinefill instead. 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:

DataArray | None

Returns:

ret – Return type depends on whether the outgrid parameter is set:

  • xarray.DataArray if outgrid is not set

  • None if outgrid is set (grid output will be stored in the file set by outgrid)

Example

>>> 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)