WCPS-Tutorial / Induced operations: how to manipulate cell values collectively
Induced operations allow to simultaneously apply a function originally working on a single cell value to all cells of a coverage. In case the range type contains more than one component, the function is applied to each cell component simultaneously. The result coverage has the same domain, but may change its base type. The idea is that for each operation available on the range type, a corresponding coverage operation is provided (“induced from the range type operation”), a concept first introduced by Ritter et al.
There is a large list of operations in WCPS, both unary and binary, similar to
programming languages. "Unary" in this context means: one coverage-valued parameter;
a unary operation may well have other scalar parameters, such as
which increments each cell value of
c by 1.
The range field selector "." which has been introduced already earlier actually
is an induced operation.
The following satellite scene will be our running example; it is displayed as a false color RGB composite with channel sequence near infrared, red, green:
Our first example uses two unary induced operations to obtain a logarithmic intensity curve of the red band:
for s in ( satScene ) return encode( (char) log(s.0), "jpeg" )
Note the induced cast operator,
(char), which ensures the result pixels
are 8-bit integers -
log() results in double-precision floating-point
pixels which is not what JPEG nor browsers like.
Arithmetic operations constitute examples for binary induced operations. In the following request the difference between two bands is derived:
for s in ( satScene ) return encode( s.0 - s.1, "jpeg" )
This we can extend to obtain the Normalized Difference Vegetation Index (NDVI) from the near infrared and red bands of a Landsat scene:
for s in ( satScene ) return encode( (char) ( (s.0-s.1)/(s.0+s.1) ), "jpeg" )
Again, we apply a cast to obtain displayable pixel types.
Going one step further we can highlight vegetation areas by applying a threshold to the expression. To this end we make use of a comparison operator:
for s in ( satScene ) return encode( (s.0-s.1)/(s.0+s.1) > 0.6, "jpeg" )
The result pixel type is boolean, that is: a binary image with 0 and 1 values:
Later we will see how such areas can be measured.
Finally, here is another somewhat more involved real-life example: The temperature plot of a suitable satellite spectral band is retrieved by:
for c in ( rgb ) return encode( 1282.71 / ( ln( (666.09/((17.04/254)*(c.red-1)))+1 ) ) - 273.15, "jpeg" )
not) play an important role in the context of conditional evaluation.
See manual: inducedExpr