Skip to main content

Hi,

I prepared the evalscript and processRequest script for Batch processing to calculate the mean of the Sentinel-1 VV and VH. I am not sure if the script is correct or not?! Is there any way to test to be sure? Or maybe you can check it out yourself?!

Kind regards,
Behzad

evalscript

evalscript = """
//VERSION=3
function setup() {
return {
input: ["VV", "VH","dataMask"],
output: { id:"default", bands: 2,sampleType: SampleType.FLOAT32},
mosaicking: Mosaicking.ORBIT
}
}

// Function to calculate the average of the bands

function calculateAverage(samples) {
var sum = 0;
var nValid = 0;
for (let i = 0; i < samples.length; i++) {
var sample = samples[i];
if (sample.dataMask != 0) {
nValid++;
sum += sample;
}
}
return sum / nValid;
}


function evaluatePixel(samples) {

var vv_mean = calculateAverage(samples.VV)
var vh_mean = calculateAverage(samples.VH)
return [vv_mean,vh_mean]
}
"""

processRequest

payload = {
"processRequest": {
"input": {
"bounds": {
"bbox": [
8.44,
41.31,
9.66,
43.1
],
"properties": {
"crs": "http://www.opengis.net/def/crs/EPSG/0/32635"
}
},
"data": [
{
"type": "S1GRD",
"dataFilter": {
"timeRange": {
"from": "2017-11-15T00:00:00Z",
"to": "2017-11-15T23:00:00Z"
},
"acquisitionMode": "IW",
"polarization": "DV",
"orbitDirection ": "ASCENDING"
},
"processing": {
"backCoeff": "GAMMA0_ELLIPSOID",
"orthorectify": "true"
}
}
]
},
"output": {
"width": 1000,
"height": 1000,
"responses": [{
"identifier": "default",
"format": {
"type": "image/tiff"
}
}]
},
"evalscript": evalscript
},
"tilingGrid": {
"id": 0,
"resolution": 10.0
},
"bucketName": "<MyBucket>",
"description": "VH/VV mean ASCENDING "
}

Hi,

There are several approaches to testing your script. First of all, in the Batch Processing workflow, when you analyse your request, your Evalscript is checked for any mistakes (typos). However, this does not tell you if the script you have does what you expect it to do!

Personally, to check a request before I run a Batch Request that consumes a lot of PUs, I use the Requests Builder. I find that it allows me to run an Evalscript quickly and easily over a small region without having to write lines of Python code. I also use it in combination with EOBrowser to quickly look at the imagery available for my area of interest.

For example in your case, a quick look at EOBrowser shows that there are no images matching your request on 2017-11-15. Testing for another date (2017-11-13) with Requests Builder throws an error.

To fix it, you could loop through the samples in the evaluatePixel function (Option 1 below) or if you want to keep everything in calculateAverage, then add the band to the function (Option 2 below).

Option 1

//VERSION=3
function setup() {
return {
input: ["VV", "VH","dataMask"],
output: { id:"default", bands: 2, sampleType: SampleType.FLOAT32},
mosaicking: "ORBIT"
};
}

function evaluatePixel(samples) {

var sum_vv = 0;
var sum_vh = 0;
var nValid = 0;

for (let i = 0; i < samples.length; i++) {
if (samples[i].dataMask != 0) {
nValid++;
sum_vv += samples[i].VV;
sum_vh += samples[i].VH;
}
}

return [sum_vv / nValid, sum_vh / nValid];
}

Option 2

//VERSION=3
function setup() {
return {
input: ["VV", "VH","dataMask"],
output: { id:"default", bands: 2,sampleType: SampleType.FLOAT32},
mosaicking: Mosaicking.ORBIT
}
}

// Function to calculate the average of the bands

function calculateAverage(samples, band) {
var sum = 0;
var nValid = 0;
for (let i = 0; i < samples.length; i++) {
var sample = samples[i];
if (sample.dataMask != 0) {
nValid++;
sum += sample[band];
}
}
return sum / nValid;
}


function evaluatePixel(samples) {

var vv_mean = calculateAverage(samples, "VV")
var vh_mean = calculateAverage(samples, "VH")

return [vv_mean,vh_mean]
}

Reply