1NEARNEIGHBOR(1) Generic Mapping Tools NEARNEIGHBOR(1)
2
3
4
6 nearneighbor - A "Nearest neighbor" gridding algorithm
7
9 nearneighbor [ xyzfile(s) ] -Gout_grdfile
10 -Ixinc[unit][=|+][/yinc[unit][=|+]] -Nsectors[/min_sectors]
11 -Rwest/east/south/north[r] -Ssearch_radius[m|c|k|K] [ -Eempty ] [ -F ]
12 [ -H[i][nrec] ] [ -Lflag ] [ -V ] [ -W ] [ -:[i|o] ] [
13 -bi[s|S|d|D[ncol]|c[var1/...]] ] [ -fcolinfo ]
14
16 nearneighbor reads arbitrarily located (x,y,z[,w]) triples [quadru‐
17 plets] from standard input [or xyzfile(s)] and uses a nearest neighbor
18 algorithm to assign an average value to each node that have one or more
19 points within a radius centered on the node. The average value is com‐
20 puted as a weighted mean of the nearest point from each sector inside
21 the search radius. The weighting function used is w(r) = 1 / (1 + d ^
22 2), where d = 3 * r / search_radius and r is distance from the node.
23 This weight is modulated by the observation points' weights [if sup‐
24 plied].
25
26 xyzfile(s)
27 3 [or 4, see -W] column ASCII file(s) [or binary, see -b] hold‐
28 ing (x,y,z[,w]) data values. If no file is specified,
29 nearneighbor will read from standard input.
30
31 -G Give the name of the output grid file.
32
33 -I x_inc [and optionally y_inc] is the grid spacing. Optionally,
34 append a suffix modifier. Geographical (degrees) coordinates:
35 Append m to indicate arc minutes or c to indicate arc seconds.
36 If one of the units e, k, i, or n is appended instead, the
37 increment is assumed to be given in meter, km, miles, or nauti‐
38 cal miles, respectively, and will be converted to the equivalent
39 degrees longitude at the middle latitude of the region (the con‐
40 version depends on ELLIPSOID). If /y_inc is given but set to 0
41 it will be reset equal to x_inc; otherwise it will be converted
42 to degrees latitude. All coordinates: If = is appended then the
43 corresponding max x (east) or y (north) may be slightly adjusted
44 to fit exactly the given increment [by default the increment may
45 be adjusted slightly to fit the given domain]. Finally, instead
46 of giving an increment you may specify the number of nodes
47 desired by appending + to the supplied integer argument; the
48 increment is then recalculated from the number of nodes and the
49 domain. The resulting increment value depends on whether you
50 have selected a gridline-registered or pixel-registered grid;
51 see Appendix B for details. Note: if -Rgrdfile is used then
52 grid spacing has already been initialized; use -I to override
53 the values.
54
55 -N The circular area centered on each node is divided into sectors
56 sectors. Average values will only be computed if there is at
57 least one value inside at least min_sectors of the sectors for a
58 given node. Nodes that fail this test are assigned the value
59 NaN (but see -E). If min_sectors is omitted, each sector needs
60 to have at least one value inside it. [Default is quadrant
61 search with at least 50% coverage, i.e., sectors = 4 and
62 min_sectors = 2]. Note that only the nearest value per sector
63 enters into the averaging, not all values inside the circle.
64
65 -R xmin, xmax, ymin, and ymax specify the Region of interest. For
66 geographic regions, these limits correspond to west, east,
67 south, and north and you may specify them in decimal degrees or
68 in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Append r if lower left
69 and upper right map coordinates are given instead of w/e/s/n.
70 The two shorthands -Rg and -Rd stand for global domain (0/360
71 and -180/+180 in longitude respectively, with -90/+90 in lati‐
72 tude). Alternatively, specify the name of an existing grid file
73 and the -R settings (and grid spacing, if applicable) are copied
74 from the grid. For calendar time coordinates you may either
75 give (a) relative time (relative to the selected TIME_EPOCH and
76 in the selected TIME_UNIT; append t to -JX|x), or (b) absolute
77 time of the form [date]T[clock] (append T to -JX|x). At least
78 one of date and clock must be present; the T is always required.
79 The date string must be of the form [-]yyyy[-mm[-dd]] (Gregorian
80 calendar) or yyyy[-Www[-d]] (ISO week calendar), while the clock
81 string must be of the form hh:mm:ss[.xxx]. The use of delim‐
82 iters and their type and positions must be exactly as indicated
83 (however, input, output and plot formats are customizable; see
84 gmtdefaults).
85
86 -S Sets the search_radius in same units as the grid spacing; append
87 m to indicate minutes or c to indicate seconds. Append k to
88 indicate km (implies -R and -I are in degrees, and we will use a
89 fast flat Earth approximation to calculate distance). For more
90 accuracy, use uppercase K if distances should be calculated
91 along geodesics. However, if the current ELLIPSOID is spherical
92 then great circle calculations are used.
93
95 -E Set the value assigned to empty nodes [NaN].
96
97 -F Force pixel node registration [Default is gridline registra‐
98 tion]. (Node registrations are defined in GMT Cookbook Appendix
99 B on grid file formats.)
100
101 -H Input file(s) has header record(s). If used, the default number
102 of header records is N_HEADER_RECS. Use -Hi if only input data
103 should have header records [Default will write out header
104 records if the input data have them]. Blank lines and lines
105 starting with # are always skipped. Not used with binary data.
106
107 -L Boundary condition flag may be x or y or xy indicating data is
108 periodic in range of x or y or both set by -R, or flag may be g
109 indicating geographical conditions (x and y are lon and lat).
110 [Default is no boundary conditions].
111
112 -V Selects verbose mode, which will send progress reports to stderr
113 [Default runs "silently"].
114
115 -: Toggles between (longitude,latitude) and (latitude,longitude)
116 input and/or output. [Default is (longitude,latitude)]. Append
117 i to select input only or o to select output only. [Default
118 affects both].
119
120 -W Input data have a 4th column containing observation point
121 weights. These are multiplied with the geometrical weight fac‐
122 tor to determine the actual weights used in the calculations.
123
124 -bi Selects binary input. Append s for single precision [Default is
125 d (double)]. Uppercase S or D will force byte-swapping.
126 Optionally, append ncol, the number of columns in your binary
127 input file if it exceeds the columns needed by the program. Or
128 append c if the input file is netCDF. Optionally, append
129 var1/var2/... to specify the variables to be read. [Default is
130 3 (or 4 if -W is set) columns].
131
132 -f Special formatting of input and/or output columns (time or geo‐
133 graphical data). Specify i or o to make this apply only to
134 input or output [Default applies to both]. Give one or more
135 columns (or column ranges) separated by commas. Append T (abso‐
136 lute calendar time), t (relative time in chosen TIME_UNIT since
137 TIME_EPOCH), x (longitude), y (latitude), or f (floating point)
138 to each column or column range item. Shorthand -f[i|o]g means
139 -f[i|o]0x,1y (geographic coordinates).
140
142 Regardless of the precision of the input data, GMT programs that create
143 grid files will internally hold the grids in 4-byte floating point
144 arrays. This is done to conserve memory and furthermore most if not
145 all real data can be stored using 4-byte floating point values. Data
146 with higher precision (i.e., double precision values) will lose that
147 precision once GMT operates on the grid or writes out new grids. To
148 limit loss of precision when processing data you should always consider
149 normalizing the data prior to processing.
150
152 To create a gridded data set from the file seaMARCII_bathy.lon_lat_z
153 using a 0.5 min grid, a 5 km search radius, using an octant search, and
154 set empty nodes to -9999:
155
156 nearneighbor seaMARCII_bathy.lon_lat_z -R242/244/-22/-20 -I0.5m -E-9999
157 -Gbathymetry.grd -S5k -N8
158
159 To make a global grid file from the data in geoid.xyz using a 1 degree
160 grid, a 200 km search radius, spherical distances, using an quadrant
161 search, and set nodes to NaN only when fewer than two quadrants contain
162 at least one value:
163
164 nearneighbor geoid.xyz -R0/360/-90/90 -I1 -Lg -Ggeoid.grd -S200K -N4/2
165
167 blockmean(1), blockmedian(1), blockmode(1), GMT(1), surface(1), trian‐
168 gulate(1)
169
170
171
172GMT 4.5.6 10 Mar 2011 NEARNEIGHBOR(1)