surface

Grid table data using adjustable tension continuous curvature splines

Synopsis

gmt surface [ table ] -Goutputfile.nc -Iincrement -Rregion [ -Aaspect_ratio|m ] [ -Cconvergence_limit[%] ] [ -Jparameters ] [ -Dbreakline_file[+z[level]] ] [ -Lllower ] [ -Luupper ] [ -Mmax_radius ] [ -Nmax_iterations ] [ -Q ] [ -Ssearch_radius[m|s] ] [ -T[i|b]tension_factor ] [ -V[level] ] [ -Zover-relaxation_factor ] [ -aflags ] [ -bibinary ] [ -dinodata ] [ -eregexp ] [ -fflags ] [ -hheaders ] [ -iflags ] [ -qiflags ] [ -rreg ] [ -wflags ] [ -:[i|o] ] [ --PAR=value ]

Note: No space is allowed between the option flag and the associated arguments.

Description

surface reads randomly-spaced (x,y,z) triples from standard input [or table] and produces a binary grid file of gridded values z(x,y) by solving the differential equation (away from data points)

\[(1 - t) \nabla ^2(z) + t \nabla (z) = 0,\]

where t is a tension factor between 0 and 1, and \(\nabla\) indicates the Laplacian operator. Here, t = 0 gives the “minimum curvature” solution which is equivalent to SuperMISP and the ISM packages. Minimum curvature can cause undesired oscillations and false local maxima or minima (See Smith and Wessel, 1990), and you may wish to use t > 0 to suppress these effects. Experience suggests t ~ 0.25 usually looks good for potential field data and t should be larger (t ~ 0.35) for steep topography data. t = 1 gives a harmonic surface (no maxima or minima are possible except at control data points). It is recommended that the user pre-process the data with blockmean, blockmedian, or blockmode to avoid spatial aliasing and eliminate redundant data. You may impose lower and/or upper bounds on the solution. These may be entered in the form of a fixed value, a grid with values, or simply be the minimum/maximum input data values. Natural boundary conditions are applied at the edges, except for geographic data with 360-degree range where we apply periodic boundary conditions in the longitude direction.

Required Arguments

table

One or more ASCII (or binary, see -bi[ncols][type]) data table file(s) holding a number of data columns. If no tables are given then we read from standard input.

-Goutputfile.nc

Output file name. Output is a binary 2-D .nc file. Note that the smallest grid dimension must be at least 4.

-Ixinc[+e|n][/yinc[+e|n]]

x_inc [and optionally y_inc] is the grid spacing. Geographical (degrees) coordinates: Optionally, append an increment unit. Choose among m to indicate arc minutes or s to indicate arc seconds. If one of the units e, f, k, M, n or u 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 y_inc is given but set to 0 it will be reset equal to x_inc; otherwise it will be converted to degrees latitude. All coordinates: If +e is appended then the corresponding max x (east) or y (north) 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 number of nodes desired by appending +n to the supplied integer argument; the increment is then recalculated from the number of nodes, the registration, and the domain. The resulting increment value depends on whether you have selected a gridline-registered or pixel-registered grid; see GMT File Formats for details. Note: If -Rgrdfile is used then the grid spacing and the registration have already been initialized; use -I and -r to override these values.

-Rxmin/xmax/ymin/ymax[+r][+uunit]

Specify the region of interest. (See full description) (See cookbook information).

Optional Arguments

-Aaspect_ratio|m

Aspect ratio. If desired, grid anisotropy can be added to the equations. Enter aspect_ratio, where dy = dx / aspect_ratio relates the grid dimensions. For geographic data, you may use -Am to set the aspect ratio to the cosine of the mean latitude [Default = 1 assumes isotropic grid.]

-Cconvergence_limit[%]

Convergence limit. Iteration is assumed to have converged when the maximum absolute change in any grid value is less than convergence_limit. (Units same as data z units). Alternatively, give limit in percentage of rms deviation by appending %. [Default is scaled to 1e-4 of the root-mean-square deviation of the data from a best-fit (least-squares) plane.]. This is the final convergence limit at the desired grid spacing; for intermediate (coarser) grids the effective convergence limit is divided by the grid spacing multiplier.

-Jparameters

Specify the projection. Select the data map projection. This projection is only used to add a referencing info to the grid formats that support it. E.g. netCDF, GeoTIFF, and others supported by GDAL.

-Dbreakline[+z[level]]

Use xyz data in the breakline file as a ‘soft breakline’. A ‘soft breakline’ is a line whose vertices will be used to constrain the nearest grid nodes without any further interpolation. A coastline or a lake shore are good examples of ‘soft breaklines’. Multi-segments files are accepted. If your lines do not have z-values or you wish to override those with a constant z-value, then append +zlevel to the filename. If no value is given then we default to 0.

-Lllower and -Luupper

Impose limits on the output solution. llower sets the lower bound. lower can be the name of a grid file with lower bound values, a fixed value, d to set to minimum input value, or u for unconstrained [Default]. uupper sets the upper bound and can be the name of a grid file with upper bound values, a fixed value, d to set to maximum input value, or u for unconstrained [Default]. Grid files used to set the limits may contain NaNs. In the presence of NaNs, the limit of a node masked with NaN is unconstrained.

-Mmax_radius

After solving for the surface, apply a mask so that nodes farther than max_radius away from a data constraint is set to NaN [no masking]. Append a distance unit (see Units) if needed. One can also select the nodes to mask by using the -Mn_cellsc form. Here n_cells means the number of cells around the node controlled by a data point. As an example -M0c means that only the cell where point lies is filled, -M1c keeps one cell beyond that (i.e. makes a 3x3 neighborhood), and so on.

-Nmax_iterations

Number of iterations. Iteration will cease when convergence_limit is reached or when number of iterations reaches max_iterations. This is the final iteration limit at the desired grid spacing; for intermediate (coarser) grids the effective iteration limit is scaled by the grid spacing multiplier [Default is 500].

-Q

Suggest grid dimensions which have a highly composite greatest common factor. This allows surface to use several intermediate steps in the solution, yielding faster run times and better results. The sizes suggested by -Q can be achieved by altering -R and/or -I. You can recover the -R and -I you want later by using grdsample or grdcut on the output of surface.

-Ssearch_radius[m|s]

Search radius. Enter search_radius in same units as x,y data; append m to indicate arc minutes or s for arc seconds. This is used to initialize the grid before the first iteration; it is not worth the time unless the grid lattice is prime and cannot have regional stages. [Default = 0.0 and no search is made.]

-T[i|b]tension_factor

Tension factor[s]. These must be between 0 and 1. Tension may be used in the interior solution (above equation, where it suppresses spurious oscillations) and in the boundary conditions (where it tends to flatten the solution approaching the edges). Using zero for both values results in a minimum curvature surface with free edges, i.e., a natural bicubic spline. Use -Titension_factor to set interior tension, and -Tbtension_factor to set boundary tension. If you do not prepend i or b, both will be set to the same value. [Default = 0 for both gives minimum curvature solution.]

-V[level]

Select verbosity level [w]. -V3 will report the convergence after each iteration; -V will report only after each regional grid is converged. (See full description) (See cookbook information).

-Zover-relaxation_factor

Over-relaxation factor. This parameter is used to accelerate the convergence; it is a number between 1 and 2. A value of 1 iterates the equations exactly, and will always assure stable convergence. Larger values overestimate the incremental changes during convergence, and will reach a solution more rapidly but may become unstable. If you use a large value for this factor, it is a good idea to monitor each iteration with the -Vi option. [Default = 1.4 converges quickly and is almost always stable.]

-a[[col=]name[,]] (more …)

Set aspatial column associations col=name.

-bi[ncols][t] (more …)

Select native binary format for primary input. [Default is 3 input columns].

-dinodata (more …)

Replace input columns that equal nodata with NaN.

-e[~]“pattern” | -e[~]/regexp/[i] (more …)

Only accept data records that match the given pattern.

-f[i|o]colinfo (more …)

Specify data types of input and/or output columns.

-h[i|o][n][+c][+d][+msegheader][+rremark][+ttitle] (more …)

Skip or produce header record(s). Not used with binary data.

-icols[+l][+ddivisor][+sscale][+ooffset][,][,t[word]] (more …)

Select input columns and transformations (0 is first column, t is trailing text, append word to read one word only).

-qi[~]rows[+ccol][+a|f|s] (more …)

Select input rows or data range(s) [default is all rows].

-r[g|p] (more …)

Set node registration [gridline].

-wy|a|w|d|h|m|s|cperiod[/phase][+ccol] (more …)

Convert an input coordinate to a cyclical coordinate.

-:[i|o] (more …)

Swap 1st and 2nd column on input and/or output.

-^ or just -

Print a short message about the syntax of the command, then exit (NOTE: on Windows just use -).

-+ or just +

Print an extensive usage (help) message, including the explanation of any module-specific option (but not the GMT common options), then exit.

-? or no arguments

Print a complete usage (help) message, including the explanation of all options, then exit.

--PAR=value

Temporarily override a GMT default setting; repeatable. See gmt.conf for parameters.

Grid Values Precision

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.

Units

For map distance unit, append unit d for arc degree, m for arc minute, and s for arc second, or e for meter [Default], f for foot, k for km, M for statute mile, n for nautical mile, and u for US survey foot. By default we compute such distances using a spherical approximation with great circles (-jg) using the authalic radius (see PROJ_MEAN_RADIUS). You can use -jf to perform “Flat Earth” calculations (quicker but less accurate) or -je to perform exact geodesic calculations (slower but more accurate; see PROJ_GEODESIC for method used).

Examples

Note: Below are some examples of valid syntax for this module. The examples that use remote files (file names starting with @) can be cut and pasted into your terminal for testing. Other commands requiring input files are just dummy examples of the types of uses that are common but cannot be run verbatim as written.

To grid 5 by 5 minute gravity block means from the ASCII data in hawaii_5x5.xyg, using a tension_factor = 0.25, a convergence_limit = 0.1 milligal, writing the result to a file called hawaii_grd.nc, and monitoring each iteration, try:

gmt surface hawaii_5x5.xyg -R198/208/18/25 -I5m -Ghawaii_grd.nc -T0.25 -C0.1 -Vi

Gridding Geographic Data: Boundary Conditions

The surface finite difference algorithm is Cartesian at heart, hence the ad hoc option to change the aspect ratio for a suitable mean latitude (-A). When geographic data are supplied and the output grid has a 360 degree longitude range we will impose periodic boundary conditions in longitude. However, no equivalent geographic boundary condition can be applied at the poles since the finite difference solution will not be valid there (actual spacing between the nodes at the poles is zero). If you attempt this type of gridding you will be severely warned but the calculations will continue. Because the result is a geographic grid, the GMT i/o machinery will interfere and detect inconsistencies at the pole points and replace all values along a pole with their mean value. This will introduce further distortion into the grid near the poles. We recommend you instead consider spherical gridding for global data sets; see greenspline (for modest data sets) or sphinterpolate.

Gridding Geographic Data: Setting Increments

Specifying grid increments in distance units (meters, km, etc.) for geographic (lon, lat) grids triggers a conversion from the given increment to the equivalent increment in degrees. This is done differently for longitude and latitude and also depends on chosen ellipsoid, but ultimately is a great-circle approximation. For latitude we divide your y-increment with the number of you chosen unit per degree latitude, while for longitude we divide your x-increment by the number of such units per degree along the mid-parallel in your region. The resulting degree increments may therefore not exactly match the increments you entered explicitly. Hence, there may be rounding off in ways you don’t want and cannot easily control, resulting in prime grid dimensions. You can handle the situation via -Q but with the never-ending decimals in some increments that is still a challenge. Another approach is to not grid geographic data using length units as increments, due to the above conversion. It may be cleaner to specify grid intervals in spherical degrees, minutes or seconds. That way you can control the grid dimensions directly and avoid the round-off. Alternatively, if your region is far from Equator and your are concerned about the difference in longitude and latitude increments in degrees you could project all data to a local projection (e.g., UTM) to yield units of meters, and then grid the projected data using meters as the final grid increment. Either approach avoids “ugly” increments like 0.161697s and will let you specify intervals that are easily divisible into the range. If increment choice is dictated by a need for a desired increment in meters then the projection route will yield better results.

Bugs

surface will complain when more than one data point is found for any node and suggest that you run blockmean, blockmedian, or blockmode first. If you did run these decimators and still get this message it usually means that your grid spacing is so small that you need more decimals in the output format used. You may specify more decimal places by editing the parameter FORMAT_FLOAT_OUT in your gmt.conf file prior to running the decimators or choose binary input and/or output using single or double precision storage.

Note that only gridline registration is possible with surface. If you need a pixel-registered grid you can resample a gridline registered grid using grdsample -T.

References

Smith, W. H. F, and P. Wessel, 1990, Gridding with continuous curvature splines in tension, Geophysics, 55, 293-305.