In the Browser, you can view two kinds of statistical information for your imagery, both for a point, a non-intersecting polygon or a non-intersecting multipolygon:
- A line chart of values through time,
- A histogram of raw values that are visually presented with colors on the map
To enable statistical features, an evalscript supporting statistical API should be used in your layers.
Statistics are calculated on the indicator values themselves (and not on RGB presentation of the values), so the evalscript needs to have additional outputs defined, which return the values without conversion to color. For example, statistics can be calculated for values of a band B04 or for an index like NDVI.
Additionally, the evalscript should include dataMask to exclude no-data values from the calculation (no-data pixels often have value 0, which could skew the statistics), and it’s also recommended to check for presence of clouds, so we can exclude them as well (cloudy pixels usually have very high values, which could also skew the results). The user can exclude any pixels from the statistics, for example snow or water.
The evalscript should contain the following outputs, with the exact same names:
- default: Needed for visualization. A visualization output that defines what will be displayed on the map. The visualization can return any visual presentation of the data, like a single value grayscale, an RGB visualization, color gradient, etc. The output element can be an array with a single element (grayscale), 3 elements (R, G, B) or 4 elements (R, G, B, transparency)
- index: Needed for histogram. Returning the raw values of your index, enabling the histogram functionality. Use FLOAT32 format to include decimals and negative values. The output element should be an array with a single element.
- eobrowserStats: Needed for line chart. An output containing the index values and optionally cloud cover information, used for line chart generation. Cloud information allows us to filter the values by the selected maximum cloud coverage. Use FLOAT32 format to include decimals and negative values. The output element can be an array with one element (no cloud cover filtering), 2 or more elements (last element should be cloud cover information).
- dataMask: Needed for line chart. A dataMask output to take no-data values into account.
Here is an example evalscript for NDVI:
//VERSION=3
function setup() {
return {
input: ["B04", "B08", "SCL","dataMask"],
//The four outputs should be set up here in the setup function, and defined under the evaluatePixel function.
output: [
{ id: "default", bands: 4 },
{ id: "index", bands: 1, sampleType: 'FLOAT32' },
{ id: "eobrowserStats", bands: 2, sampleType: 'FLOAT32' },
{ id: "dataMask", bands: 1 }
]
};
}
// Optional filtering for clouds using the Sentinel-2A SCL band (values 1, 2, 7, 8, 9, 10, 11 are either clouds or snow)
function isCloud (scl) {
if ([1, 2, 7, 8, 9, 10, 11].includes(scl)) {
return false;
}
}
function evaluatePixel(samples) {
let val = index(samples.B08, samples.B04); // NDVI calculation
let imgVals = null;
const indexVal = samples.dataMask === 1 ? val : NaN; //NDVI index without no-data values
const cloud = isCloud(samples.SCL) //calling in our cloud filtering function as a cloud variable
//Define the RGB NDVI visualization and write it into imgVals
if (val<-0.5) imgVals = [0.05,0.05,0.05,samples.dataMask];
else if (val<-0.2) imgVals = [0.75,0.75,0.75,samples.dataMask];
else if (val<-0.1) imgVals = [0.86,0.86,0.86,samples.dataMask];
else if (val<0) imgVals = [0.92,0.92,0.92,samples.dataMask];
else if (val<0.025) imgVals = [1,0.98,0.8,samples.dataMask];
else if (val<0.05) imgVals = [0.93,0.91,0.71,samples.dataMask];
else if (val<0.075) imgVals = [0.87,0.85,0.61,samples.dataMask];
else if (val<0.1) imgVals = [0.8,0.78,0.51,samples.dataMask];
else if (val<0.125) imgVals = [0.74,0.72,0.42,samples.dataMask];
else if (val<0.15) imgVals = [0.69,0.76,0.38,samples.dataMask];
else if (val<0.175) imgVals = [0.64,0.8,0.35,samples.dataMask];
else if (val<0.2) imgVals = [0.57,0.75,0.32,samples.dataMask];
else if (val<0.25) imgVals = [0.5,0.7,0.28,samples.dataMask];
else if (val<0.3) imgVals = [0.44,0.64,0.25,samples.dataMask];
else if (val<0.35) imgVals = [0.38,0.59,0.21,samples.dataMask];
else if (val<0.4) imgVals = [0.31,0.54,0.18,samples.dataMask];
else if (val<0.45) imgVals = [0.25,0.49,0.14,samples.dataMask];
else if (val<0.5) imgVals = [0.19,0.43,0.11,samples.dataMask];
else if (val<0.55) imgVals = [0.13,0.38,0.07,samples.dataMask];
else if (val<0.6) imgVals = [0.06,0.33,0.04,samples.dataMask];
else imgVals = [0,0.27,0,samples.dataMask];
// Return the 4 inputs and define content for each one
return {
default: imgVals,
index: [indexVal],
eobrowserStats: [indexVal,cloud?1:0],
dataMask: [samples.dataMask]
};
}
See the script in Browser.
The evalscript can be used directly in Browser using the custom script function, or setup for the layer within the Configuration Manager.
When you create a custom layer, it is possible to select the same layer in Browser. See the section 2 of this FAQ to see how to visualize your configuration in Browser, or follow the steps below.
- In Browser, first select your configuration from the Configuration dropdown on the top of the Search tab.
- Select the desired data source (if all layers in the selected configuration have the same data source, only one will be available).
- Make sure to set the appropriate time range and zoom in to the area where your data is available.
- Click Search and select one of the results.
- Select your layer in the Visualization tab.
- When you have your layer displayed, draw a point or a polygon on the map and inspect the statistics features.
Comments
Article is closed for comments.