Skip to content

Use complete and consistent descriptions for grid and outgrid #2695

@seisman

Description

@seisman

I'll take the current grdcut documentation (https://www.pygmt.org/v0.10.0/api/generated/pygmt.grdcut.html) as an example.

Currently, the docstring says:

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.

When grid or outgrid is a netCDF file, it can actually have more modifiers (http://docs.generic-mapping-tools.org/latest/grdcut.html):

ingrid[=ID|?varname][+bband][+ddivisor][+ninvalid][+ooffset][+sscale]

Input grid file. Optionally, append =ID for reading a specific file format [Default is =nf] or ?varname for a specific netCDF variable [Default is the first 2-D grid found by GMT] (See full description). The following modifiers are supported:

+b - Select a band (for images only) [Default is 0].

+d - Divide data values by the given divisor [Default is 1].

+n - Replace data values matching invalid with NaN.

+o - Offset data values by the given offset [Default is 0].

+s - Scale data values by the given scale [Default is 1].

Note: Any offset is added after any scaling.

-Goutgrid[=ID][+ddivisor][+ninvalid][+ooffset|a][+sscale|a][:driver[dataType][+coptions]]

Give the name of the output grid file. Optionally, append =ID for writing a specific file format (See full description). The following modifiers are supported:

+d - Divide data values by given divisor [Default is 1].

+n - Replace data values matching invalid with a NaN.

+o - Offset data values by the given offset, or append a for automatic range offset to preserve precision for integer grids [Default is 0].

+s - Scale data values by the given scale, or append a for automatic scaling to preserve precision for integer grids [Default is 1].

Note: Any offset is added before any scaling. +sa also sets +oa (unless overridden). To write specific formats via GDAL, use =gd and supply driver (and optionally dataType) and/or one or more concatenated GDAL -co options using +c. See the “Writing grids and images” cookbook section for more details.

I think we should improve the docstrings to have a complete description about grids. Since the same description will be used in many different function docstrings, we can define new docstring placeholders in COMMON_DOCSTRINGS (https://github.com/GenericMappingTools/pygmt/blob/1e4845432cd3d0c575cc12c711c10735bbd5f289/pygmt/helpers/decorators.py#L17C1-L17C18).

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions