TREND2D

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
REMARKS
ASCII FORMAT PRECISION
EXAMPLES
SEE ALSO
REFERENCES

NAME

trend2d − Fit a [weighted] [robust] polynomial model for z = f(x,y) to xyz[w] data.

SYNOPSIS

trend2d −Fxyzmrw −Nn_model[r] [ xyz[w]file ] [ −Ccondition_number ] [ −H[i][nrec] ][ −I[confidence_level] ] [ −V ] [ −W ] [ −:[i|o] ] [ −b[i|o][s|S|d|D[ncol]|c[var1/...]] ] [ −f[i|o]colinfo ]

DESCRIPTION

trend2d reads x,y,z [and w] values from the first three [four] columns on standard input [or xyz[w]file] and fits a regression model z = f(x,y) + e by [weighted] least squares. The fit may be made robust by iterative reweighting of the data. The user may also search for the number of terms in f(x,y) which significantly reduce the variance in z. n_model may be in [1,10] to fit a model of the following form (similar to grdtrend):

m1 + m2*x + m3*y + m4*x*y + m5*x*x + m6*y*y + m7*x*x*x + m8*x*x*y + m9*x*y*y + m10*y*y*y.

The user must specify −Nn_model, the number of model parameters to use; thus, −N4 fits a bilinear trend, −N6 a quadratic surface, and so on. Optionally, append r to perform a robust fit. In this case, the program will iteratively reweight the data based on a robust scale estimate, in order to converge to a solution insensitive to outliers. This may be handy when separating a "regional" field from a "residual" which should have non-zero mean, such as a local mountain on a regional surface.

−F

Specify up to six letters from the set {x y z m r w} in any order to create columns of ASCII [or binary] output. x = x, y = y, z = z, m = model f(x,y), r = residual z - m, w = weight used in fitting.

−N

Specify the number of terms in the model, n_model, and append r to do a robust fit. E.g., a robust bilinear model is −N4r.

OPTIONS

xyz[w]file

ASCII [or binary, see −b] file containing x,y,z [w] values in the first 3 [4] columns. If no file is specified, trend2d will read from standard input.

−C

Set the maximum allowed condition number for the matrix solution. trend2d fits a damped least squares model, retaining only that part of the eigenvalue spectrum such that the ratio of the largest eigenvalue to the smallest eigenvalue is condition_#. [Default: condition_# = 1.0e06. ].

−H

Input file(s) has header record(s). If used, the default number of header records is N_HEADER_RECS. Use −Hi if only input data should have header records [Default will write out header records if the input data have them]. Blank lines and lines starting with # are always skipped.

−I

Iteratively increase the number of model parameters, starting at one, until n_model is reached or the reduction in variance of the model is not significant at the confidence_level level. You may set −I only, without an attached number; in this case the fit will be iterative with a default confidence level of 0.51. Or choose your own level between 0 and 1. See remarks section.

−V

Selects verbose mode, which will send progress reports to stderr [Default runs "silently"].

−W

Weights are supplied in input column 4. Do a weighted least squares fit [or start with these weights when doing the iterative robust fit]. [Default reads only the first 3 columns.]

−:

Toggles between (longitude,latitude) and (latitude,longitude) input and/or output. [Default is (longitude,latitude)]. Append i to select input only or o to select output only. [Default affects both].

−bi

Selects binary input. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Optionally, append ncol, the number of columns in your binary input file if it exceeds the columns needed by the program. Or append c if the input file is netCDF. Optionally, append var1/var2/... to specify the variables to be read. [Default is 3 (or 4 if −W is set) input columns].

−bo

Selects binary output. Append s for single precision [Default is d (double)]. Uppercase S or D will force byte-swapping. Optionally, append ncol, the number of desired columns in your binary output file. [Default is 1-6 columns as set by −F].

−f

Special formatting of input and/or output columns (time or geographical data). Specify i or o to make this apply only to input or output [Default applies to both]. Give one or more columns (or column ranges) separated by commas. Append T (absolute calendar time), t (relative time in chosen TIME_UNIT since TIME_EPOCH), x (longitude), y (latitude), or f (floating point) to each column or column range item. Shorthand −f[i|o]g means −f[i|o]0x,1y (geographic coordinates).

REMARKS

The domain of x and y will be shifted and scaled to [-1, 1] and the basis functions are built from Chebyshev polynomials. These have a numerical advantage in the form of the matrix which must be inverted and allow more accurate solutions. In many applications of trend2d the user has data located approximately along a line in the x,y plane which makes an angle with the x axis (such as data collected along a road or ship track). In this case the accuracy could be improved by a rotation of the x,y axes. trend2d does not search for such a rotation; instead, it may find that the matrix problem has deficient rank. However, the solution is computed using the generalized inverse and should still work out OK. The user should check the results graphically if trend2d shows deficient rank. NOTE: The model parameters listed with −V are Chebyshev coefficients; they are not numerically equivalent to the m#s in the equation described above. The description above is to allow the user to match −N with the order of the polynomial surface. For evaluating Chebyshev polynomials, see grdmath.

The −Nn_modelr (robust) and −I (iterative) options evaluate the significance of the improvement in model misfit Chi-Squared by an F test. The default confidence limit is set at 0.51; it can be changed with the −I option. The user may be surprised to find that in most cases the reduction in variance achieved by increasing the number of terms in a model is not significant at a very high degree of confidence. For example, with 120 degrees of freedom, Chi-Squared must decrease by 26% or more to be significant at the 95% confidence level. If you want to keep iterating as long as Chi-Squared is decreasing, set confidence_level to zero.

A low confidence limit (such as the default value of 0.51) is needed to make the robust method work. This method iteratively reweights the data to reduce the influence of outliers. The weight is based on the MedAL ATIME COORDINATES

When the output grid type is netCDF, the coordinates will be labeled "longitude", "latitude", or "time" based on the attributes of the input data or grid (if any) or on the −f or −R options. For example, both −f0x −f1t and −R90w/90e/0t/3t will result in a longitude/time grid. When the x, y, or z coordinate is time, it will be stored in the grid as relative time since epoch as specified by TIME_UNIT and TIME_EPOCH in the .gmtdefaults file or on the command line. In addition, the unit attribute of the time variable will indicate both this unit and epoch.

EXAMPLES

To take log10 of the average of 2 files, use

grdmath file1.grd file2.grd ADD 0.5 MUL LOG10 = file3.grd

Given the file ages.grd, which holds seafloor ages in m.y., use the relation depth(in m) = 2500 + 350 * sqrt (age) to estimate normal seafloor depths:

grdmath ages.grd SQRT 350 MUL 2500 ADD = depths.grd

To find the angle a (in degrees) of the largest principal stress from the stress tensor given by the three files s_xx.grd s_yy.grd, and s_xy.grd from the relation tan (2*a) = 2 * s_xy / (s_xx - s_yy), use

grdmath 2 s_xy.grd MUL s_xx.grd s_yy.grd SUB DIV ATAN2 2 DIV = direction.grd

To calculate the fully normalized spherical harmonic of degree 8 and order 4 on a 1 by 1 degree world map, using the real amplitude 0.4 and the imaginary amplitude 1.1:

grdmath −R0/360/-90/90 −I1 8 4 YML 1.1 MUL EXCH 0.4 MUL ADD = harm.grd

To extract the locations of local maxima that exceed 100 mGal in the file faa.grd:

grdmath faa.grd DUP EXTREMA 2 EQ MUL DUP 100 GT MUL 0 NAN = z.grd
grd2xyz
z.grd −S > max.xyz

REFERENCES

Abramowitz, M., and I. A. Stegun, 1964, Handbook of Mathematical Functions