public final class cwmath
extends java.lang.Object
The math tool combines earth data using a mathematical expression.
cwmath - combines earth data using a mathematical expression.
cwmath [OPTIONS] input
cwmath [OPTIONS] input1 [input2 ...] output
-c, --scale=FACTOR/OFFSET | none
-e, --expr=EXPRESSION
-h, --help
-k, --skip-missing
-l, --longname=STRING
-m, --missing=VALUE
-p, --parser=TYPE
-s, --size=TYPE
-t, --template=VARIABLE
-u, --units=STRING
-v, --verbose
--version
The math tool combines earth data using a mathematical expression. The expression takes the form:
variable = formula
where the variable is the output variable to create and the formula is a mathematical combination of input variables. The formula may contain a number of standard operators, for example addition and subtraction, as well as functions such as sine and cosine and numerical and symbolic constants. The formula syntax can follow one of two standards specified by the --parser option: the legacy syntax as originally supported by the math tool, or Java syntax that takes advantage of the full java.lang.Math function library and in some cases allows for simpler expressions. See http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html for a full list of java.lang.Math functions. A comparison of the most common language features is as follows:
Language Feature | Legacy Parser Syntax | Java Parser Syntax |
---|---|---|
Unary plus | +x | Unsupported |
Unary minus | -x | -x |
Addition | x + y | x + y |
Subtraction | x - y | x - y |
Multiplication | x * y | x * y |
Division | x / y | x / y |
Modulus | x % y or mod (x, y) | x % y |
Exponentiation | x ^ y | pow (x, y) |
Bitwise AND | and (x, y) | x & y |
Bitwise OR | or (x, y) | x | y |
Bitwise XOR | xor (x, y) | x ^ y |
Bitwise NOT | not (x) | ~x |
Less than | x < y | x < y |
Greater than | x > y | x > y |
Less than or equal to | x <= y | x <= y |
Greater than or equal to | x >= y | x >= y |
Not equal to | x != y | x != y |
Equal to | x == y | x == y |
Boolean conjunction | x && y | x && y |
Boolean disjunction | x || y | x || y |
Boolean negation | !x | !x |
Sine | sin (x) | sin (x) |
Cosine | cos (x) | cos (x) |
Tangent | tan (x) | tan (x) |
Arcsine | asin (x) | asin (x) |
Arccosine | acos (x) | acos (x) |
Arctangent | atan (x) | atan (x) |
Hyperbolic sine | sinh (x) | sinh (x) |
Hyperbolic cosine | cosh (x) | cosh (x) |
Hyperbolic tangent | tanh (x) | tanh (x) |
Inverse hyperbolic sine | asinh (x) | asinh (x) |
Inverse hyperbolic cosine | acosh (x) | acosh (x) |
Inverse hyperbolic tangent | atanh (x) | atanh (x) |
Natural log | ln (x) | log (x) |
Base 10 log | log (x) | log10 (x) |
Polar coordinate angle | angle (y, x) | atan2 (y, x) |
Absolute value | abs (x) | abs (x) |
Random value [0..1] | rand() | random() |
Square root | sqrt (x) | sqrt (x) |
Sum of values | sum (x1, x2, ...) | sum (x1, x2, ...) |
Conditional operator | select (condition, x, y) | (condition ? x : y) |
Hexadecimal constant | hex ("0xffff") | 0xffff |
Data value masking | mask (x, flag, bitmask) | ((flag & bitmask) == 0 ? x : NaN) |
Value of e (2.71828...) | e | E |
Value Pi (3.14159...) | pi | PI |
Not-a-Number as 64-bit | nan | NaN |
Test for Not-a-Number | Unsupported | isNaN (x) |
Note that in legacy parser expressions, boolean result values are evaluated to either 1.0 (true) or 0.0 (false).
integer = value/factor + offsetThe default is '0.01/0'. If 'none' is specified, the expression result is considered to be an integer and stored directly in the output value. This option is ignored for floating-point storage types, namely if --size is 'float' or 'double' or if the template variable type is floating-point.
0 on success, > 0 on failure. Possible causes of errors:
The following shows the correction of AVHRR channel 2 data for solar zenith angle. The output variable is named 'avhrr_ch2_corr' and is written to the input file:
phollema$ cwmath -v --units "percent" --longname "AVHRR channel 2 corrected" --expr "avhrr_ch2_corr = avhrr_ch2/cos(sun_zenith*pi/180)" 2003_104_1513_n17_er.hdf cwmath: Reading input 2003_104_1513_n17_er.hdf cwmath: Creating avhrr_ch2_corr variable cwmath: Computing row 0 cwmath: Computing row 100 cwmath: Computing row 200 cwmath: Computing row 300 ...
Another example below shows the computation of Normalized Difference Vegetation Index (NDVI):
phollema$ cwmath -v --longname "Normalized Difference Vegetation Index" --expr "ndvi = (avhrr_ch2 - avhrr_ch1)/(avhrr_ch2 + avhrr_ch1)" 2003_104_1513_n17_er.hdf cwmath: Reading input 2003_104_1513_n17_er.hdf cwmath: Creating ndvi variable cwmath: Computing row 0 cwmath: Computing row 100 cwmath: Computing row 200 cwmath: Computing row 300 ...
In order to demonstrate the use of the 'mask' function, the example below shows the masking of the 'sst' variable using the 'cloud' variable. Note that a hexadecimal value is used to determine which values from the cloud mask are used in the masking procedure. Since the cloud data is represented by 8-bit bytes, the hexadecimal mask value need only specify two hexadecimal digits. In this case, the value '0x6f' represents bits 1, 2, 3, 4, 6, and 7 (for all cloud mask bits, the value would be '0xff'):
phollema$ cwmath -v --template sst --expr 'sst_masked = mask (sst, cloud, hex ("0x6f"))' 2003_104_1513_n17_er.hdf cwmath: Reading input 2003_104_1513_n17_er.hdf cwmath: Creating sst_masked variable cwmath: Computing row 0 cwmath: Computing row 100 cwmath: Computing row 200 cwmath: Computing row 300 ...
A final example below shows how the tool may be used to compute complex formulas using a Unix Bourne shell script. The example computes the theoretical AVHRR channel 3b albedo at night for NOAA-17 using actual channel 3b temperatures and channel 3b emission temperatures estimated from channel 4 and 5:
#!/bin/sh input=$1 T3E_A=6.82947 T3E_B=0.97232 T3E_C=1.66366 ZERO_C=273.15 t3="(avhrr_ch3 + $ZERO_C)" t4="(avhrr_ch4 + $ZERO_C)" t5="(avhrr_ch5 + $ZERO_C)" t3e="($T3E_A + $T3E_B*$t4 + $T3E_C*($t4 - $t5))" planck_c1=1.1910427e-5 planck_c2=1.4387752 w3=2669.3554 c3b_a=1.702380 c3b_b=0.997378 rad3="(($planck_c1*($w3^3)) / (e^(($planck_c2*$w3)/($c3b_a + $c3b_b*$t3)) - 1.0))" rad3e="(($planck_c1*($w3^3)) / (e^(($planck_c2*$w3)/($c3b_a + $c3b_b*$t3e)) - 1.0))" alb3="(100*(1 - $rad3/$rad3e))" cwmath -v --longname "AVHRR channel 3 albedo" --units "percent" \ --expr "avhrr_ch3_albedo=$alb3" $input
Modifier and Type | Method and Description |
---|---|
static void |
main(java.lang.String[] argv)
Performs the main function.
|