grdmath
- 贡献者
Caesar(自然资源部第一海洋研究所),周茂
- 官方文档
- 简介
网格数据的逆波兰表示法(RPN)计算
grdmath 使用逆波兰表示法对网格文件或常量进行逐元素运算,最终结果写入到新的网格文件。若不给定网格文件,则必须使用 -R 与 -I 选项生成网格文件。 = outgrid 可在计算中多次使用以保存中间结果。复杂的或频繁使用的运算可赋值给变量或使用宏。
语法
gmt grdmath [ -Amin_area[/min_level/max_level][+a[g|i][s|S]][+l|r][+ppercent] ] [ -Dresolution[+f] ] [ -Iincrement ] [ -M ] [ -N ] [ -Rregion ] [ -S ] [ -V[level] ] [ -aflags ] [ -bibinary ] [ -dinodata[+ccol] ] [ -eregexp ] [ -fflags ] [ -ggaps ] [ -hheaders ] [ -iflags ] [ -nflags ] [ -rreg ] [ -x[[-]n] ] [ --PAR=value ] operand [ operand ] OPERATOR [ operand ] OPERATOR … = outgrid
必选选项
- operand
如果 operand 是一个文件,GMT 将试着以网格文件的形式读取该文件。如果非文件,将被解析为 其他符号 或数字常量。
- = outgrid
输出网格文件名
可选选项
- -Amin_area[/min_level/max_level][+a[g|i][s|S]][+l|r][+ppercent]
不绘制面积过小的区域(湖泊或岛屿),或不绘制某个级别的湖泊边界。
在绘制湖泊时,若不管湖泊的面积大小而把所有湖泊的边界都画上去,可能导致图看上去比较乱,该选项用于对湖泊进行筛选。面积小于 min_area 平方千米或者湖泊级别不在 [min_level,max_level] 范围的边界都不会被绘制。默认值为 0/0/4,即绘制所有湖泊边界,即绘制0到4级所有级别的面积大于0的湖泊。
对于level=2,即湖岸线,包括常规的湖以及很宽的河流。加上 +r 则只绘制河流,加上 +l 则只绘制常规湖。
对于南极洲而言,因为有冰层的存在,所以海岸线有多种处理方式:
+ai 用ice shell boundary作为南极洲的海岸线,默认值
+ag 以ice grounding line作为海岸线
+as 忽略南纬60度以南的海岸线,用户可以使用 plot 绘制自己的南极洲海岸线
+aS 忽略南纬60度以北的海岸线
+pprecent:一个多边形,降低精度后,边数减少,面积变化,当面积变化过大时再绘制这个多边形就不合适了,该子选项用于去除那些面积与最高精度面积之比小于 percent 的多边形。
备注
该选项仅适用于 LDISTG 运算符
- -Dresolution[+f]
设置 LDISTG 运算符使用的数据集的分辨率: (f)ull,(h)igh,(i)ntermediate,(l)ow 和 (c)rude。默认的 l 选项将数据集缩减为原本的 20%。如果请求的分辨率不存在,使用 +f 选项会自动选择一个较低的分辨率。
备注
该选项仅适用于 LDISTG 运算符。
- -Ixinc[+e|n][/yinc[+e|n]]
指定X和Y方向的网格间隔
xinc 和 yinc 为 X 和 Y 方向的网格间隔。对于地理坐标,可以指定网格间隔单位 [默认单位为度]
+e 微调X和Y方向范围的最大值,使得其是网格间隔的整数倍(默认会微调网格间隔以适应给定的数据范围)
+n 表明 xinc 和 yinc 不是网格间隔,而是X和Y方向的节点数。此时会根据节点数、网格区域范围以及网格配准方式重新计算网格间隔。
注意:
若 yinc 设置为0,则表示其与 xinc 相同
若使用 -Rgrdfile 选项,则网格间隔和配准方式已经根据网格文件自动初始化,此时依然可以使用 -I 和 -r 覆盖相应的值
- -M
默认的导数计算单位为 z_units/x(或 y )_units。使用该选项,可以将 dx 和 dy 的单位从度变为平地球近似下的米,因此最终单位变为 z_units/meter
- -N
操作多个网格时,关闭严格的范围匹配检查 [默认情况下,要求每个网格的范围和第一个网格的范围不能超过阈值,该阈值为第一个网格间隔的 10^-4]
- -Rxmin/xmax/ymin/ymax[+r][+uunit] (more …)
指定数据范围
- -S
将下一个运算应用到所有的网格中,使最终结果为一个网格。必须在列出所有网格后才能使用该选项。 注 :仅能在改选项后使用 reduce 运算符,包括 ADD,AND,MAD,LMSSCL,MAX,MEAN,MEDIAN,MIN,MODE,MUL,RMS,STD,SUB,VAR 或 XOR
- -V[level] (more …)
设置 verbose 等级 [w]
- -acol=name[,…] (more …)
设置非空间数据项与数据列之间的对应关系
- -bi[ncols][type][w][+l|b] (more …)
设置二进制输入数据的格式
- -dinodata (more …)
将输入数据中值为 nodata 的列替换为 NaN
- -e[~]“pattern” | -e[~]/regexp/[i] (more …)
筛选或剔除匹配指定模式的数据记录
- -f[i|o]colinfo (more …)
指定输入或输出列的数据类型
- -g[a]x|y|d|X|Y|D|[col]zgap[+n|p] (more …)
确定数据或线段的间断
- -h[i|o][n][+c][+d][+msegheader][+rremark][+ttitle] (more …)
跳过或生成指定数目的头段记录
- -icols[+l][+sscale][+ooffset][,…][,t[word]] (more …)
设置输入数据列及简单变换(0表示第一列,t 表示文本列)
- -n[b|c|l|n][+a][+bBC][+c][+tthreshold] (more …)
设置网格文件的插值方式
- -r[g|p] (more …)
设置网格配置方式 [默认为网格线配准]
- -x[[-]n] (more …)
限制多核算法中能使用的核数(需要GMT开启OpenMP支持)
- -^ 或 -
显示简短的帮助信息,包括模块简介和基本语法信息(Windows下只能使用 -)
- -+ 或 +
显示帮助信息,包括模块简介、基本语法以及模块特有选项的说明
- -? 或无参数
显示完整的帮助信息,包括模块简介、基本语法以及所有选项的说明
- --PAR=value
临时修改GMT参数的值,可重复多次使用。参数列表见 配置参数
运算符
Operator 为运算符名称; args 分别表示输入参数和输出参数个数; Returns 中的 A B C … 等字符表示输入参数。
Operator |
Args |
Returns |
ABS |
1 1 |
abs (A) |
ACOS |
1 1 |
acos (A) |
ACOSH |
1 1 |
acosh (A) |
ACOT |
1 1 |
acot (A) |
ACSC |
1 1 |
acsc (A) |
ADD |
2 1 |
A + B |
AND |
2 1 |
B if A == NaN, else A |
ARC |
2 1 |
Return arc(A,B) on [0 pi] |
AREA |
0 1 |
Area of each gridnode cell (in km^2 if geographic) |
ASEC |
1 1 |
asec (A) |
ASIN |
1 1 |
asin (A) |
ASINH |
1 1 |
asinh (A) |
ATAN |
1 1 |
atan (A) |
ATAN2 |
2 1 |
atan2 (A, B) |
ATANH |
1 1 |
atanh (A) |
BCDF |
3 1 |
Binomial cumulative distribution function for p = A, n = B, and x = C |
BPDF |
3 1 |
Binomial probability density function for p = A, n = B, and x = C |
BEI |
1 1 |
Kelvin function bei (A) |
BER |
1 1 |
Kelvin function ber (A) |
BITAND |
2 1 |
A & B (bitwise AND operator) |
BITLEFT |
2 1 |
A << B (bitwise left-shift operator) |
BITNOT |
1 1 |
~A (bitwise NOT operator, i.e., return two’s complement) |
BITOR |
2 1 |
A | B (bitwise OR operator) |
BITRIGHT |
2 1 |
A >> B (bitwise right-shift operator) |
BITTEST |
2 1 |
1 if bit B of A is set, else 0 (bitwise TEST operator) |
BITXOR |
2 1 |
A ^ B (bitwise XOR operator) |
BLEND |
3 1 |
Blend A and B using weights in C (0-1 range) as A*C + B*(1-C) |
CAZ |
2 1 |
Cartesian azimuth from grid nodes to stack x,y (i.e., A, B) |
CBAZ |
2 1 |
Cartesian back-azimuth from grid nodes to stack x,y (i.e., A, B) |
CDIST |
2 1 |
Cartesian distance between grid nodes and stack x,y (i.e., A, B) |
CDIST2 |
2 1 |
As CDIST but only to nodes that are != 0 |
CEIL |
1 1 |
ceil (A) (smallest integer >= A) |
CHICRIT |
2 1 |
Chi-squared critical value for alpha = A and nu = B |
CHICDF |
2 1 |
Chi-squared cumulative distribution function for chi2 = A and nu = B |
CHIPDF |
2 1 |
Chi-squared probability density function for chi2 = A and nu = B |
COMB |
2 1 |
Combinations n_C_r, with n = A and r = B |
CORRCOEFF |
2 1 |
Correlation coefficient r(A, B) |
COS |
1 1 |
cos (A) (A in radians) |
COSD |
1 1 |
cos (A) (A in degrees) |
COSH |
1 1 |
cosh (A) |
COT |
1 1 |
cot (A) (A in radians) |
COTD |
1 1 |
cot (A) (A in degrees) |
CSC |
1 1 |
csc (A) (A in radians) |
CSCD |
1 1 |
csc (A) (A in degrees) |
CUMSUM |
2 1 |
Cumulative sum of each row (B=±1|3) or column (B=±2|4) in A. Sign of B gives direction of summation |
CURV |
1 1 |
Curvature of A (Laplacian) |
D2DX2 |
1 1 |
d^2(A)/dx^2 2nd derivative |
D2DY2 |
1 1 |
d^2(A)/dy^2 2nd derivative |
D2DXY |
1 1 |
d^2(A)/dxdy 2nd derivative |
D2R |
1 1 |
Converts Degrees to Radians |
DDX |
1 1 |
d(A)/dx Central 1st derivative |
DAYNIGHT |
3 1 |
1 where sun at (A, B) shines and 0 elsewhere, with C transition width |
DDY |
1 1 |
d(A)/dy Central 1st derivative |
DEG2KM |
1 1 |
Converts spherical degrees to kilometers |
DENAN |
2 1 |
Replace NaNs in A with values from B |
DILOG |
1 1 |
dilog (A) |
DIV |
2 1 |
A / B |
DOT |
2 1 |
2-D (Cartesian) or 3-D (geographic) dot products between nodes and stack (A, B) unit vector(s) |
DUP |
1 2 |
Places duplicate of A on the stack |
ECDF |
2 1 |
Exponential cumulative distribution function for x = A and lambda = B |
ECRIT |
2 1 |
Exponential distribution critical value for alpha = A and lambda = B |
EPDF |
2 1 |
Exponential probability density function for x = A and lambda = B |
ERF |
1 1 |
Error function erf (A) |
ERFC |
1 1 |
Complementary Error function erfc (A) |
EQ |
2 1 |
1 if A == B, else 0 |
ERFINV |
1 1 |
Inverse error function of A |
EXCH |
2 2 |
Exchanges A and B on the stack |
EXP |
1 1 |
exp (A) |
FACT |
1 1 |
A! (A factorial) |
EXTREMA |
1 1 |
Local Extrema: +2/-2 is max/min, +1/-1 is saddle with max/min in x, 0 elsewhere |
FCDF |
3 1 |
F cumulative distribution function for F = A, nu1 = B, and nu2 = C |
FCRIT |
3 1 |
F distribution critical value for alpha = A, nu1 = B, and nu2 = C |
FISHER |
3 1 |
Fisher probability density function at nodes for center lon = A, lat = B, with kappa = C |
FLIPLR |
1 1 |
Reverse order of values in each row |
FLIPUD |
1 1 |
Reverse order of values in each column |
FLOOR |
1 1 |
floor (A) (greatest integer <= A) |
FMOD |
2 1 |
A % B (remainder after truncated division) |
FPDF |
3 1 |
F probability density function for F = A, nu1 = B, and nu2 = C |
GE |
2 1 |
1 if A >= B, else 0 |
GT |
2 1 |
1 if A > B, else 0 |
HSV2RGB |
3 3 |
Convert h,s,v triplets to r,g,b triplets, with h = A (0-360), s = B and v = C (both in 0-1) |
HSV2RGB |
3 3 |
Convert h,s,v triplets to r,g,b triplets, with h = A (0-360), s = B and v = C (0-1) |
HSV2XYZ |
3 3 |
Convert h,s,v triplets to x,t,z triplets, with h = A (0-360), s = B and v = C (0-1) |
HYPOT |
2 1 |
hypot (A, B) = sqrt (A*A + B*B) |
I0 |
1 1 |
Modified Bessel function of A (1st kind, order 0) |
I1 |
1 1 |
Modified Bessel function of A (1st kind, order 1) |
IFELSE |
3 1 |
B if A != 0, else C |
IN |
2 1 |
Modified Bessel function of A (1st kind, order B) |
INRANGE |
3 1 |
1 if B <= A <= C, else 0 |
INSIDE |
1 1 |
1 when inside or on polygon(s) in A, else 0 |
INV |
1 1 |
1 / A |
ISFINITE |
1 1 |
1 if A is finite, else 0 |
ISNAN |
1 1 |
1 if A == NaN, else 0 |
J0 |
1 1 |
Bessel function of A (1st kind, order 0) |
J1 |
1 1 |
Bessel function of A (1st kind, order 1) |
JN |
2 1 |
Bessel function of A (1st kind, order B) |
K0 |
1 1 |
Modified Kelvin function of A (2nd kind, order 0) |
K1 |
1 1 |
Modified Bessel function of A (2nd kind, order 1) |
KEI |
1 1 |
Kelvin function kei (A) |
KER |
1 1 |
Kelvin function ker (A) |
KM2DEG |
1 1 |
Converts kilometers to spherical degrees |
KN |
2 1 |
Modified Bessel function of A (2nd kind, order B) |
KURT |
1 1 |
Kurtosis of A |
LAB2HSV |
3 3 |
Convert l,a,b triplets to h,s,v triplets |
LAB2RGB |
3 3 |
Convert l,a,b triplets to r,g,b triplets |
LAB2XYZ |
3 3 |
Convert l,a,b triplets to x,y,z triplets |
LCDF |
1 1 |
Laplace cumulative distribution function for z = A |
LCRIT |
1 1 |
Laplace distribution critical value for alpha = A |
LDIST |
1 1 |
Compute minimum distance (in km if -fg) from lines in multi-segment ASCII file A |
LDIST2 |
2 1 |
As LDIST, from lines in ASCII file B but only to nodes where A != 0 |
LDISTG |
0 1 |
As LDIST, but operates on the GSHHG dataset (see -A, -D for options). |
LE |
2 1 |
1 if A <= B, else 0 |
LOG |
1 1 |
log (A) (natural log) |
LOG10 |
1 1 |
log10 (A) (base 10) |
LOG1P |
1 1 |
log (1+A) (accurate for small A) |
LOG2 |
1 1 |
log2 (A) (base 2) |
LMSSCL |
1 1 |
LMS (Least Median of Squares) scale estimate (LMS STD) of A |
LMSSCLW |
2 1 |
Weighted LMS (Least Median of Squares) scale estimate (LMS STD) of A for weights in B |
LOWER |
1 1 |
The lowest (minimum) value of A |
LPDF |
1 1 |
Laplace probability density function for z = A |
LRAND |
2 1 |
Laplace random noise with mean A and std. deviation B |
LT |
2 1 |
1 if A < B, else 0 |
MAD |
1 1 |
Median Absolute Deviation (L1 STD) of A |
MAX |
2 1 |
Maximum of A and B |
MEAN |
1 1 |
Mean value of A |
MEANW |
2 1 |
Weighted mean value of A for weights in B |
MEDIAN |
1 1 |
Median value of A |
MEDIANW |
2 1 |
Weighted median value of A for weights in B |
MIN |
2 1 |
Minimum of A and B |
MOD |
2 1 |
A mod B (remainder after floored division) |
MODE |
1 1 |
Mode value (Least Median of Squares) of A |
MODEW |
2 1 |
Weighted mode value (Least Median of Squares) of A for weights in B |
MUL |
2 1 |
A * B |
NAN |
2 1 |
NaN if A == B, else A |
NEG |
1 1 |
-A |
NEQ |
2 1 |
1 if A != B, else 0 |
NORM |
1 1 |
Normalize (A) so max(A)-min(A) = 1 |
NOT |
1 1 |
NaN if A == NaN, 1 if A == 0, else 0 |
NRAND |
2 1 |
Normal, random values with mean A and std. deviation B |
OR |
2 1 |
NaN if B == NaN, else A |
PCDF |
2 1 |
Poisson cumulative distribution function for x = A and lambda = B |
PDIST |
1 1 |
Compute minimum distance (in km if -fg) from points in ASCII file A |
PDIST2 |
2 1 |
As PDIST, from points in ASCII file B but only to nodes where A != 0 |
PERM |
2 1 |
Permutations n_P_r, with n = A and r = B |
PLM |
3 1 |
Associated Legendre polynomial P(A) degree B order C |
PLMg |
3 1 |
Normalized associated Legendre polynomial P(A) degree B order C (geophysical convention) |
POINT |
1 2 |
Compute mean x and y from ASCII file A and place them on the stack |
POP |
1 0 |
Delete top element from the stack |
POW |
2 1 |
A ^ B |
PPDF |
2 1 |
Poisson distribution P(x,lambda), with x = A and lambda = B |
PQUANT |
2 1 |
The B’th Quantile (0-100%) of A |
PQUANTW |
3 1 |
The C’th weighted quantile (0-100%) of A for weights in B |
PSI |
1 1 |
Psi (or Digamma) of A |
PV |
3 1 |
Legendre function Pv(A) of degree v = real(B) + imag(C) |
QV |
3 1 |
Legendre function Qv(A) of degree v = real(B) + imag(C) |
R2 |
2 1 |
R2 = A^2 + B^2 |
R2D |
1 1 |
Convert Radians to Degrees |
RAND |
2 1 |
Uniform random values between A and B |
RCDF |
1 1 |
Rayleigh cumulative distribution function for z = A |
RCRIT |
1 1 |
Rayleigh distribution critical value for alpha = A |
RGB2HSV |
3 3 |
Convert r,g,b triplets to h,s,v triplets, with r = A, g = B, and b = C (all in 0-255 range) |
RGB2LAB |
3 3 |
Convert r,g,b triplets to l,a,b triplets, with r = A, g = B, and b = C (in 0-255 range) |
RGB2XYZ |
3 3 |
Convert r,g,b triplets to x,y,x triplets, with r = A, g = B, and b = C (in 0-255 range) |
RINT |
1 1 |
rint (A) (round to integral value nearest to A) |
RMS |
1 1 |
Root-mean-square of A |
RMSW |
1 1 |
Root-mean-square of A for weights in B |
RPDF |
1 1 |
Rayleigh probability density function for z = A |
ROLL |
2 0 |
Cyclicly shifts the top A stack items by an amount B |
ROTX |
2 1 |
Rotate A by the (constant) shift B in x-direction |
ROTY |
2 1 |
Rotate A by the (constant) shift B in y-direction |
SDIST |
2 1 |
Spherical (Great circle|geodesic) distance (in km) between nodes and stack (A, B) |
SDIST2 |
2 1 |
As SDIST but only to nodes that are != 0 |
SAZ |
2 1 |
Spherical azimuth from grid nodes to stack lon, lat (i.e., A, B) |
SBAZ |
2 1 |
Spherical back-azimuth from grid nodes to stack lon, lat (i.e., A, B) |
SEC |
1 1 |
sec (A) (A in radians) |
SECD |
1 1 |
sec (A) (A in degrees) |
SIGN |
1 1 |
sign (+1 or -1) of A |
SIN |
1 1 |
sin (A) (A in radians) |
SINC |
1 1 |
sinc (A) (sin (pi*A)/(pi*A)) |
SIND |
1 1 |
sin (A) (A in degrees) |
SINH |
1 1 |
sinh (A) |
SKEW |
1 1 |
Skewness of A |
SQR |
1 1 |
A^2 |
SQRT |
1 1 |
sqrt (A) |
STD |
1 1 |
Standard deviation of A |
STDW |
2 1 |
Weighted standard deviation of A for weights in B |
STEP |
1 1 |
Heaviside step function: H(A) |
STEPX |
1 1 |
Heaviside step function in x: H(x-A) |
STEPY |
1 1 |
Heaviside step function in y: H(y-A) |
SUB |
2 1 |
A - B |
SUM |
1 1 |
Sum of all values in A |
TAN |
1 1 |
tan (A) (A in radians) |
TAND |
1 1 |
tan (A) (A in degrees) |
TANH |
1 1 |
tanh (A) |
TAPER |
2 1 |
Unit weights cosine-tapered to zero within A and B of x and y grid margins |
TCDF |
2 1 |
Student’s t cumulative distribution function for t = A, and nu = B |
TCRIT |
2 1 |
Student’s t distribution critical value for alpha = A and nu = B |
TN |
2 1 |
Chebyshev polynomial Tn(-1<t<+1,n), with t = A, and n = B |
TPDF |
2 1 |
Student’s t probability density function for t = A, and nu = B |
TRIM |
3 1 |
Alpha-trim C to NaN if values fall in tails A and B (in percentage) |
UPPER |
1 1 |
The highest (maximum) value of A |
VAR |
1 1 |
Variance of A |
VARW |
2 1 |
Weighted variance of A for weights in B |
VPDF |
3 1 |
Von Mises density distribution P(x,mu,kappa), with x = A, mu = B, and kappa = C |
WCDF |
3 1 |
Weibull cumulative distribution function for x = A, scale = B, and shape = C |
WCRIT |
3 1 |
Weibull distribution critical value for alpha = A, scale = B, and shape = C |
WPDF |
3 1 |
Weibull density distribution P(x,scale,shape), with x = A, scale = B, and shape = C |
WRAP |
1 1 |
wrap A in radians onto [-pi,pi] |
XOR |
2 1 |
0 if A == NaN and B == NaN, NaN if B == NaN, else A |
XYZ2HSV |
3 3 |
Convert x,y,x triplets to h,s,v triplets |
XYZ2LAB |
3 3 |
Convert x,y,x triplets to l,a,b triplets |
XYZ2RGB |
3 3 |
Convert x,y,x triplets to r,g,b triplets |
Y0 |
1 1 |
Bessel function of A (2nd kind, order 0) |
Y1 |
1 1 |
Bessel function of A (2nd kind, order 1) |
YLM |
2 2 |
Re and Im orthonormalized spherical harmonics degree A order B |
YLMg |
2 2 |
Cos and Sin normalized spherical harmonics degree A order B (geophysical convention) |
YN |
2 1 |
Bessel function of A (2nd kind, order B) |
ZCDF |
1 1 |
Normal cumulative distribution function for z = A |
ZPDF |
1 1 |
Normal probability density function for z = A |
ZCRIT |
1 1 |
Normal distribution critical value for alpha = A |
其他符号
以下符号都具有特殊意义:
PI |
3.1415926… |
E |
2.7182818… |
EULER |
0.5772156… |
PHI |
1.6180339… (golden ratio) |
EPS_F |
1.192092896e-07 (single precision epsilon |
XMIN |
Minimum x value |
XMAX |
Maximum x value |
XRANGE |
Range of x values |
XINC |
x increment |
NX |
The number of x nodes |
YMIN |
Minimum y value |
YMAX |
Maximum y value |
YRANGE |
Range of y values |
YINC |
y increment |
NY |
The number of y nodes |
X |
Grid with x-coordinates |
Y |
Grid with y-coordinates |
XNORM |
Grid with normalized [-1 to +1] x-coordinates |
YNORM |
Grid with normalized [-1 to +1] y-coordinates |
XCOL |
Grid with column numbers 0, 1, …, NX-1 |
YROW |
Grid with row numbers 0, 1, …, NY-1 |
NODE |
Grid with node numbers 0, 1, …, (NX*NY)-1 |
NODEP |
Grid with node numbers in presence of pad |
上述符号均可以作为变量使用,当其为多个数时,逐元素操作。
运算符注意事项
对于笛卡尔坐标,运算符 MEAN,MEDIAN,MODE,LMSSCL,MAD, PQUANT,RMS,STD 和 VAR 将返回基于给定网格的值。对于地理坐标,GMT 将施行球面加权运算,其中每个节点的值都由该点代表的地理区域加权得到。
SDIST 计算堆栈上的点 (lon,lat) 与所有网格点的球面距离,单位为 km。网格范围和点的坐标单位均为度。类似地,SAZ 和 SBAZ 分别用来球面方位角以及球面反方位角,单位也为度。如果设置了 -fg 或隐含该选项,LDIST 和 PDIST 以 km 为单位计算球面距离,否则返回笛卡尔距离。注 : 如果 PROJ_ELLIPSOID 为椭球,则计算结果为大地线(测地线)的长度。这可能导致计算比较慢,但可以通过 PROJ_GEODESIC 中设置使用其他算法以平衡精度和效率。
LDISTG 和 LDIST 作用类似,但是 LDISTG 使用 GSHHG 数据运算。其中 GSHHG 数据来自 -D 和 -A 选项。
POINT 读取一个 ASCII 文件,计算 x 和 y 的平均值并放在堆栈中。如果输入数据为地理坐标,使用平均 3D 向量来确定平均位置。
PLM 和 PLMg 运算符用来计算 L 阶 M 次的缔合勒让德函数;M 参数的范围应该满足 0 <= M <= L,参数为纬度的正弦值。 PLM 运算符没有经过标准化,并且乘以 phase (-1)^M。 PLMg 使用大地测量/地球物理常见的标准化。使用 -M 参数可以附加球谐系数 C 和 S。 PLM 在较高的阶次就会出现溢出,具体和纬度相关, PLMg 则可以保证在 3000 阶以下都不会溢
YLM 和 YLGM 用于计算网格所有位置的 L 阶 M 次标准化后的球谐函数,0 <= M <= L。结果返回两个网格,一个为球谐函数的实部网格,一个为虚部网格。使用 POP 可保存其中的任意一个,也可以使用两个连续的 = file.nc 同时保存。
正交归一化的复数谐函数主要用于物理学和地震学,YLM 的平方在球面上的积分为 1。在大地测量学中,YLMG 积分后的结果为 4pi。相位 (-1)^M 不包含在 YLM 和 YLMg 中。
所有导数都基于 central finite differences 和 natural boundary conditionsi,并且为笛卡尔坐标下的导数
不同参数文件名相同时,应给定相对路径或绝对路径以区分不同文件
不允许使用管道
该模块计算过程保存在堆栈中,栈中保存结果最大为 100,即不能叠加太多的操作以防溢出
所有需要半径的运算符为保证其为正值,均自动取了绝对值后计算
当使用 OpenMP 后,某些运算符将使用该能力。目前包括 LDIST,LDIST2, PDIST,PDIST2,SAZ,SBAZ,SDIST,YLM,和 grd_YLMg
DEG2KM 和 KM2DEG 只有当设置 PROJ_ELLIPSOID 为球形时才准确
DOT 在点积计算之前对二维向量进行归一化,对于三维向量,则不需要。
颜色转换函数,例如 RGB2HSV 等,不仅包括 rgb 到 hsv 等三元数的转换,还包括 lab 到 sRGB 等四元数的转换
DAYNIGHT 返回一个网格,在给定太阳位置为 (A,B) 时,面向太阳的网格点为 1,其他为 0,如果过渡宽度 C 为 0,则结果为 0 和 1 两种,如果 C 不为 0,则使用 atan 函数近似求解,因此值不为 0 或 1。
VPDF 运算符的输入数据单位为角
CUMSUM 运算符通常在行或者列结束时重置累计的值,使用 ±3 或 ±4 可以使累积的值在下一行或者列继续
位运算符 BITAND,BITLEFT,BITNOT,BITOR,BITRIGHT, BITTEST 和 BITXOR 会将网格数据中的单精度数转换为无符号的 32 位整数,然后按位运算。因此,可储存在双精度数中的最大整数为 2^24 ,更大的数都会被截断。如果被比较的数中包括 NaN ,则最终结果也为 NaN
储存、调用和清除
用户可以将中间计算结果储存到一个变量中,并在后续计算中调用该变量。这在需要对某部分进行多次重复计算时可以提高效率和可读性。保存结果需要使用特殊的运算符 STO@label , 其中 label 是变量的名称。调用该变量时,使用 [RCL]@label , RCL 是可选的。使用后要清除该变量,可以使用 CLR@label , STO 和 CLR 均不影响计算中的堆栈。
GSHHG 信息
GSHHG (The Global Self-consistent, Hierarchical, High-resolution Geography Database) 最初为 GSHHS,是一个海岸线数据库,主要有三个来源:World Vector Shorelines (WVS,不包括南极洲), CIA World Data Bank II (WDBII), 和 Atlas of the Cryosphere (AC,只包含南极洲)。除了南极洲,所有的 1 级多边形(海陆边界)都来自更准确的 WVS,所有的更高级别的多边形(2-4 级,湖泊边界、湖中岛边界和湖中岛中湖边界)来自 WDBII。南极洲的海岸线有两种:冰盖的边界和陆地的边界,可以使用 -A 选项选择。为了将 WVS 、WDBII 和 AC 数据转换为 GMT 可用的格式,GMT 已经进行了多种处理,包括:由线段组建多边形,去重,以及校正多边形之间的交叉等。每个多边形的面积已经被计算出来,因此,用户可以自己选择不绘制小于最小面积的多边形,还可以限制绘制的多边形的级别,见 -A 选项。绘制海岸线时,还可以使用不同的精细程度,其中低分辨率的海岸线是由 Douglas-Peucker 算法简化得到的。河流和边界的分类遵循 WDBII。详细细节见 GSHHG 。
点位于多边形内/外
为了确定点在多边形内,外或在边界上,GMT 会平衡数据类型以及多边形形状等因素来确定算法。对于笛卡尔坐标,GMT 使用 non-zero winding 算法,该算法非常快。对于地理坐标,如果多边形不包括两极点且多边形的经度范围不超过 360 度,同样使用该算法。否则,GMT 会采用 full spherical ray-shooting 方法。
宏
用户可以将特定的运算符组合保存为宏文件 gmtmath.macros 。文件中可以包含任意数量的宏, # 开头的行为注释。宏的格式为
name = arg1 arg2 ... arg2[ : comment]
其中,name 是宏名,当此运算符出现在命令中时,则将其简单替换为参数列表。宏不可以互相调用。下面给出一个宏例子:INCIRCLE 宏需要三个参数:半径,x0 和 y0,并将在圆内的点设置为 1,外部设置为 0
INCIRCLE = CDIST EXCH DIV 1 LE : usage: r x y INCIRCLE to return 1 inside circl
由于在宏中可能使用地理或时间常数,因此可使用 :
后加一个空格的形式作为注释的开端。
示例
计算网格点到北极的距离
gmt grdmath -Rg -I1 0 90 SDIST = dist_to_NP.nc
求两个文件的均值以及结果的 log10 函数值
gmt grdmath file1.nc file2.nc ADD 0.5 MUL LOG10 = file3.nc
给定含有海底地形年代(单位 m.y.)和深度(单位 m)网格文件 agrs.nc
,使用公式 depth(单位为 m) = 2500 + 350 * sqrt (age) 估计正常深度
gmt grdmath ages.nc SQRT 350 MUL 2500 ADD = depths.nc
从 s_xx.nc
,s_yy.nc
和 s_xy.nc
三个文件包含的应力张量中,根据
tan (2*a) = 2 * s_xy / (s_xx - s_yy) 求出最大主应力的角度,单位为度
gmt grdmath 2 s_xy.nc MUL s_xx.nc s_yy.nc SUB DIV ATAN 2 DIV = direction.nc
计算 1 度分辨率的网格上完全正则化的 8 阶 4 次球谐函数,实数和虚数的振幅分别为 0.4 和 1.1
gmt grdmath -R0/360/-90/90 -I1 8 4 YLM 1.1 MUL EXCH 0.4 MUL ADD = harm.nc
提取文件:file:faa.nc 中超过 100 mgal 的局部最大值的位置
gmt grdmath faa.nc DUP EXTREMA 2 EQ MUL DUP 100 GT MUL 0 NAN = z.nc
gmt grd2xyz z.nc -s > max.xyz
变量的使用: consider this radial wave where we store and recall the normalized radial arguments in radians
gmt grdmath -R0/10/0/10 -I0.25 5 5 CDIST 2 MUL PI MUL 5 DIV STO@r COS @r SIN MUL = wave.nc
创建一个保存 32 位浮点型 GeoTiff 文件
gmt grdmath -Rd -I10 X Y MUL = lixo.tiff=gd:GTiff
计算地理网格 data.grd
中网格点到 trace.txt
的距离,单位为 km
gmt grdmath -Rdata.grd trace.txt LDIST = dist_from_line.grd
-S 选项的使用:计算所有以 model_*.grd 为名的网格对应节点的标准差
gmt grdmath model_*.grd -S STD = std_of_models.grd
创建 0.5 度分辨率的 geotiff 网格文件,网格值为离海岸线的距离,单位为 km
gmt grdmath -RNO,IS -Dc -I.5 LDISTG = distance.tif=gd:GTIFF
参考文献
Abramowitz, M., and I. A. Stegun, 1964, Handbook of Mathematical Functions, Applied Mathematics Series, vol. 55, Dover, New York.
Holmes, S. A., and W. E. Featherstone, 2002, A unified approach to the Clenshaw summation and the recursive computation of very high degree and order normalized associated Legendre functions. Journal of Geodesy, 76, 279-299.
Press, W. H., S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery, 1992, Numerical Recipes, 2nd edition, Cambridge Univ., New York.
Spanier, J., and K. B. Oldman, 1987, An Atlas of Functions, Hemisphere Publishing Corp.