.\" Man page generated from reStructuredText. . .TH "NEARNEIGHBOR" "1gmt" "May 21, 2019" "5.4.5" "GMT" .SH NAME nearneighbor \- "Grid table data using a ""Nearest neighbor"" algorithm" . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH SYNOPSIS .sp \fBnearneighbor\fP [ \fItable\fP ] \fB\-G\fP\fIout_grdfile\fP \fB\-I\fP\fIincrement\fP \fB\-N\fP\fIsectors\fP[/\fImin_sectors\fP] \fB\-R\fP\fIregion\fP \fB\-S\fP\fIsearch_radius\fP[\fIunit\fP] [ \fB\-E\fP\fIempty\fP ] [ \fB\-V\fP[\fIlevel\fP] ] [ \fB\-W\fP ] [ \fB\-bi\fPbinary ] [ \fB\-di\fPnodata ] [ \fB\-e\fPregexp ] [ \fB\-f\fPflags ] [ \fB\-h\fPheaders ] [ \fB\-i\fPflags ] [ \fB\-n\fPflags ] [ \fB\-r\fP ] [ \fB\-:\fP[\fBi\fP|\fBo\fP] ] .sp \fBNote:\fP No space is allowed between the option flag and the associated arguments. .SH DESCRIPTION .sp \fBnearneighbor\fP reads arbitrarily located (x,y,z[,w]) triples [quadruplets] from standard input [or \fItable\fP] and uses a nearest neighbor algorithm to assign an average value to each node that have one or more points within a radius centered on the node. The average value is computed as a weighted mean of the nearest point from each sector inside the search radius. The weighting function used is w(r) = 1 / (1 + d ^ 2), where d = 3 * r / search_radius and r is distance from the node. This weight is modulated by the weights of the observation points [if supplied]. .SH REQUIRED ARGUMENTS .INDENT 0.0 .TP \fB\-G\fP\fIout_grdfile\fP Give the name of the output grid file. .UNINDENT .INDENT 0.0 .TP \fB\-I\fP\fIxinc\fP[\fIunit\fP][\fB+e\fP|\fBn\fP][/\fIyinc\fP[\fIunit\fP][\fB+e\fP|\fBn\fP]] \fIx_inc\fP [and optionally \fIy_inc\fP] is the grid spacing. Optionally, append a suffix modifier. \fBGeographical (degrees) coordinates\fP: Append \fBm\fP to indicate arc minutes or \fBs\fP to indicate arc seconds. If one of the units \fBe\fP, \fBf\fP, \fBk\fP, \fBM\fP, \fBn\fP or \fBu\fP is appended instead, the increment is assumed to be given in meter, foot, km, Mile, nautical mile or US survey foot, respectively, and will be converted to the equivalent degrees longitude at the middle latitude of the region (the conversion depends on PROJ_ELLIPSOID). If \fIy_inc\fP is given but set to 0 it will be reset equal to \fIx_inc\fP; otherwise it will be converted to degrees latitude. \fBAll coordinates\fP: If \fB+e\fP is appended then the corresponding max \fIx\fP (\fIeast\fP) or \fIy\fP (\fInorth\fP) may be slightly adjusted to fit exactly the given increment [by default the increment may be adjusted slightly to fit the given domain]. Finally, instead of giving an increment you may specify the \fInumber of nodes\fP desired by appending \fB+n\fP to the supplied integer argument; the increment is then recalculated from the number of nodes and the domain. The resulting increment value depends on whether you have selected a gridline\-registered or pixel\-registered grid; see App\-file\-formats for details. Note: if \fB\-R\fP\fIgrdfile\fP is used then the grid spacing has already been initialized; use \fB\-I\fP to override the values. .UNINDENT .INDENT 0.0 .TP \fB\-N\fP\fIsectors\fP[/\fImin_sectors\fP] The circular area centered on each node is divided into \fIsectors\fP sectors. Average values will only be computed if there is at least one value inside each of at least \fImin_sectors\fP of the sectors for a given node. Nodes that fail this test are assigned the value NaN (but see \fB\-E\fP). If \fImin_sectors\fP is omitted it is set to be at least 50% of \fIsectors\fP (i.e., rounded up to next integer). [Default is a quadrant search with 100% coverage, i.e., \fIsectors\fP = \fImin_sectors\fP = 4]. Note that only the nearest value per sector enters into the averaging; the more distant points are ignored. .UNINDENT .INDENT 0.0 .TP \fB\-R\fP\fIxmin\fP/\fIxmax\fP/\fIymin\fP/\fIymax\fP[\fB+r\fP][\fB+u\fP\fIunit\fP] (more ...) Specify the region of interest. .UNINDENT .INDENT 0.0 .TP \fB\-S\fP\fIsearch_radius\fP[\fIunit\fP] Sets the \fIsearch_radius\fP that determines which data points are considered close to a node. Append the distance unit (see UNITS). .UNINDENT .SH OPTIONAL ARGUMENTS .INDENT 0.0 .TP .B \fItable\fP 3 [or 4, see \fB\-W\fP] column ASCII file(s) [or binary, see \fB\-bi\fP] holding (x,y,z[,w]) data values. If no file is specified, \fBnearneighbor\fP will read from standard input. .UNINDENT .INDENT 0.0 .TP \fB\-E\fP\fIempty\fP Set the value assigned to empty nodes [NaN]. .UNINDENT .INDENT 0.0 .TP \fB\-V\fP[\fIlevel\fP] (more ...) Select verbosity level [c]. .UNINDENT .INDENT 0.0 .TP \fB\-W\fP Input data have a 4th column containing observation point weights. These are multiplied with the geometrical weight factor to determine the actual weights used in the calculations. .UNINDENT .INDENT 0.0 .TP \fB\-bi\fP[\fIncols\fP][\fBt\fP] (more ...) Select native binary input. [Default is 3 (or 4 if \fB\-W\fP is set) columns]. .UNINDENT .INDENT 0.0 .TP \fB\-di\fP\fInodata\fP (more ...) Replace input columns that equal \fInodata\fP with NaN. .UNINDENT .INDENT 0.0 .TP \fB\-e\fP[\fB~\fP]\fI"pattern"\fP \fB|\fP \fB\-e\fP[\fB~\fP]/\fIregexp\fP/[\fBi\fP] (more ...) Only accept data records that match the given pattern. .UNINDENT .INDENT 0.0 .TP \fB\-f\fP[\fBi\fP|\fBo\fP]\fIcolinfo\fP (more ...) Specify data types of input and/or output columns. .UNINDENT .INDENT 0.0 .TP \fB\-h\fP[\fBi\fP|\fBo\fP][\fIn\fP][\fB+c\fP][\fB+d\fP][\fB+r\fP\fIremark\fP][\fB+r\fP\fItitle\fP] (more ...) Skip or produce header record(s). .UNINDENT .INDENT 0.0 .TP \fB\-i\fP\fIcols\fP[\fB+l\fP][\fB+s\fP\fIscale\fP][\fB+o\fP\fIoffset\fP][,\fI\&...\fP] (more ...) Select input columns and transformations (0 is first column). .TP \fB\-n\fP[\fBb\fP|\fBc\fP|\fBl\fP|\fBn\fP][\fB+a\fP][\fB+b\fP\fIBC\fP][\fB+t\fP\fIthreshold\fP] Append \fB+b\fP\fIBC\fP to set any boundary conditions to be used, adding \fBg\fP for geographic, \fBp\fP for periodic, or \fBn\fP for natural boundary conditions. For the latter two you may append \fBx\fP or \fBy\fP to specify just one direction, otherwise both are assumed. [Default is geographic if grid is geographic]. .UNINDENT .INDENT 0.0 .TP \fB\-r\fP (more ...) Set pixel node registration [gridline]. .UNINDENT .INDENT 0.0 .TP \fB\-:\fP[\fBi\fP|\fBo\fP] (more ...) Swap 1st and 2nd column on input and/or output. .UNINDENT .INDENT 0.0 .TP \fB\-^\fP or just \fB\-\fP Print a short message about the syntax of the command, then exits (NOTE: on Windows just use \fB\-\fP). .TP \fB\-+\fP or just \fB+\fP Print an extensive usage (help) message, including the explanation of any module\-specific option (but not the GMT common options), then exits. .TP \fB\-?\fP or no arguments Print a complete usage (help) message, including the explanation of all options, then exits. .UNINDENT .SH UNITS .sp For map distance unit, append \fIunit\fP \fBd\fP for arc degree, \fBm\fP for arc minute, and \fBs\fP for arc second, or \fBe\fP for meter [Default], \fBf\fP for foot, \fBk\fP for km, \fBM\fP for statute mile, \fBn\fP for nautical mile, and \fBu\fP for US survey foot. By default we compute such distances using a spherical approximation with great circles. Prepend \fB\-\fP to a distance (or the unit is no distance is given) to perform "Flat Earth" calculations (quicker but less accurate) or prepend \fB+\fP to perform exact geodesic calculations (slower but more accurate). .SH GRID VALUES PRECISION .sp Regardless of the precision of the input data, GMT programs that create grid files will internally hold the grids in 4\-byte floating point arrays. This is done to conserve memory and furthermore most if not all real data can be stored using 4\-byte floating point values. Data with higher precision (i.e., double precision values) will lose that precision once GMT operates on the grid or writes out new grids. To limit loss of precision when processing data you should always consider normalizing the data prior to processing. .SH EXAMPLES .sp To create a gridded data set from the file seaMARCII_bathy.lon_lat_z using a 0.5 min grid, a 5 km search radius, using an octant search with 100% sector coverage, and set empty nodes to \-9999: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt nearneighbor seaMARCII_bathy.lon_lat_z \-R242/244/\-22/\-20 \-I0.5m \e \-E\-9999 \-Gbathymetry.nc \-S5k \-N8/8 .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .sp To make a global grid file from the data in geoid.xyz using a 1 degree grid, a 200 km search radius, spherical distances, using an quadrant search, and set nodes to NaN only when fewer than two quadrants contain at least one value: .INDENT 0.0 .INDENT 3.5 .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gmt nearneighbor geoid.xyz \-R0/360/\-90/90 \-I1 \-Lg \-Ggeoid.nc \-S200k \-N4 .ft P .fi .UNINDENT .UNINDENT .UNINDENT .UNINDENT .SH SEE ALSO .sp blockmean, blockmedian, blockmode, gmt, greenspline, sphtriangulate, surface, triangulate .SH COPYRIGHT 2019, P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe .\" Generated by docutils manpage writer. .