In 2017/11 major release we have changed the way of working with styles, see full description of changes.
In previous version, styles were split in three different groups:
- Visualized, Raw (for Custom scripts)
- Color map, Grayscale, Blue/Red, Green White Linear, Red Temperature, Index (for single values / single input band)
- RGB, RGB Advanced, Reflectance, Sentinel DN (for three-color visualization, such as True colour, False colour, etc.)
In 2017/11 version scripts consist basically of two parts, setup and evaluatePixel.
In setup part the input and output components are defined.
function setup(ds) {
setInputComponents([ds.B02, ds.B03, ds.B04]);
setOutputComponentCount(3);
}
EvaluatePixel part is the main difference between old version and 2017/11. In 2017/11 different Visualizers can be used and each Visualizer has it's own set of parameters.
- ColorGradientVisualizer (valColPairs, minVal=0.0, maxVal=1.0)
- ColormapVisualizer (valColPairs)
- DefaultVisualizer (minValue=0.0, maxValue=1.0, gain=1.0, offset=0.0, gamma=1.0)
- HighlightCompressVisualizer (minValue=0.0, maxValue=1.0, gain=1.0, offset=0.0, gamma=1.0)
- HighlightCompressVisualizerSingle (minValue=0.0, maxValue=1.0, gain=1.0, offset=0.0, gamma=1.0)
- Identity (val)
Example of evaluatePixel function bellow creates a Visualizer, where values are spanned between min and max value. Bands B04, B03 and B02 are used as data input. Each band value is then processed with specified Visualizer and function returns an array of resulting values.
let minVal = 0;
let MaxVal = 255;
let gain = 0.7;
let viz = new HighlightCompressVisualizer(minVal, maxVal, gain);
function evaluatePixel(samples) {
let val = [samples[0].B04, samples[0].B03, samples[0].B02];
return val.map(v => viz.process(v));
}
Each old style group A, B or C mentioned above can use any Visualizer and can return resulting values as arrays of values. Array sizes correspond to the Visualizer used and number of bands in input.
General formula or process for conversion of old style eval scripts to new style eval scripts can be summoned to the following examples. Examples don't use Visualizers:
Single input band / single output band
function evaluatePixel(s) {
//eval function takes inputs as defined in setInputComponents([ds.B07]);
//so using s[0].B07 we access band B07
let val = s[0].B07
return [val * 5 + 120]
}
function setup(ds) {
setInputComponents([ds.B07]);
setOutputComponentCount(1);
}
Multiple input bands / single output band
function evaluatePixel(s) {
return[0.2 * s[0].B05 + 0.3 * s[0].B06 + 0.5 * s[0].B02];
}
function setup(ds) {
setInputComponents([ds.B05, ds.B06, ds.B02]);
setOutputComponentCount(1);
}
Multiple input bands / multiple output bands
function evaluatePixel(s) {
return [
0.2 * s[0].B05 + 0.3 * s[0].B06 + 0.5 * s[0].B02,
s[0].B08,
s[0].B09
];
}
function setup(ds) {
setInputComponents([ds.B05, ds.B06, ds.B02, ds.B08, ds.B09]);
setOutputComponentCount(3);
}
General formula or process for conversion of old style Custom scripts to new style Custom scripts with Visualizers can be implemented with calling Visualizer before return.
Example:
return [
0.2 * s[0].B05 + 0.3 * s[0].B06 + 0.5 * s[0].B02,
s[0].B08,
s[0].B09
];
changes to:
let minVal = 0;
let MaxVal = 255;
let viz = new HighlightCompressVisualizer(minVal, maxVal);
function evaluatePixel(s) {
val = [
0.2 * s[0].B05 + 0.3 * s[0].B06 + 0.5 * s[0].B02,
s[0].B08,
s[0].B09
];
return val.map(v => viz.process(v));
)
General example of migration
The user sees a Custom script in new system (2017/11)
It looks like:
let minVal = 0.0;
let maxVal = 0.4;
let viz = new HighlightCompressVisualizer(minVal, maxVal);
function evaluatePixel(samples) {
let val = [samples[0].B04, samples[0].B03, samples[0].B01];
return val.map(v => viz.process(v));
}
function setup(ds) {
setInputComponents([ds.B01, ds.B03, ds.B04]);
setOutputComponentCount(3);
}
when user clicks "Save", the system responds with a warning about depreciation of styles.
If you want to use some other style, you can set Custom script accordingly.
The required changes can be implemented in two ways:
- Use new builtin scripts
- Modify your old custom script so that it uses new style as described in first part.
Basically you need to modify eval function, so that it uses input bands in your
calculations. Final results can then be returned via prefered Visualizer.
Some examples are listed below:
RGB:
let minVal = 0.0;
let maxVal = 0.4;
let viz = new HighlightCompressVisualizer(minVal, maxVal);
function evaluatePixel(samples) {
// pure RGB values
let val = [samples[0].B04, samples[0].B03, samples[0].B02];
// fill band values
// val[0] - band R
// val[1] - band G
// val[2] - band B
// copy your calculations here and take care that correct variables are used
// for different bands
// an example of simple calculation
// let val = [samples[0].B04 * 0.2,
// (samples[0].B03 + samples[0].B02) * 0.5,
// samples[0].B02 * 0.7];
return val.map(v => viz.process(v));
}
function setup(ds) {
setInputComponents([ds.B02, ds.B03, ds.B04]);
setOutputComponentCount(3);
}
In the table below are Visualizers used for different styles:
Three band values
let val = [samples[0].B04, samples[0].B03, samples[0].B02];
return val.map(v => viz.process(v));
style | viz | description |
RGB | HighlightCompressVisualizer | RGB visualization |
REFLECTANCE | Identity | Original reflectance in the range [0, 1] |
NORMALIZED | DefaultVisualizer |
Single band values
let val = [samples[0].B04, samples[0].B03, samples[0].B02];
return val.map(v => viz.process(v));