Hi all. For some analysis, I am looking at comparing a Sentinel-1 image during an event (e.g. flooding) with a collection of images preceding the event. Thus I have to get (1) an event image at a given date, and (2) a collection of images over a time range preceding the event (of which I calculate e.g. a backscatter average), and I am comparing the two.
I am trying to approach this by making a Process API data fusion request, both collections being Sentinel-1 but with the corresponding dates or dates ranges. However I am having some issues, with two select examples below:
- When trying to export
outputMetadata
(userdata
). This work well on a single collection without identifier, but fails in a data fusion with identifiers. - When, for instance, computing the average backscatter of a data collection. Works fine again for a sole collection, but also fails on data fusion.
For instance, this works:
function setup() {
return {
input: [
{bands: ["VV", "dataMask"]},
],
output: [
{id: "default", bands: 1}
],
mosaicking: "TILE",
};
}
function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
outputMetadata.userData = {"scenes": scenes.tiles}
}
function calculateAverage(samples) {
var sum = 0
var nValid = 0
for (let sample of samples) {
if (sample.dataMask != 0) {
nValid++
sum += sample.{pol}
}
}
return sum / nValid
}
function evaluatePixel(samples) {
return [calculateAverage(samples)]
}
But not this (data fusion request with a beforeEvent
and afterEvent
S1 sources, only showing the code pertaining to beforeEvent
):
function setup() {
return {
input: [
{bands: ["VV", "dataMask"], datasource: "beforeEvent"},
{bands: ["VV", "dataMask"], datasource: "afterEvent"},
],
output: [
{id: "default", bands: 1}
],
mosaicking: "TILE",
};
}
function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
outputMetadata.userData = {"scenesBeforeEvent": scenes.beforeEvent.tiles}
}
function calculateAverage(samples) {
var sum = 0
var nValid = 0
for (let sample of samples) {
if (sample.dataMask != 0) {
nValid++
sum += sample.VV
}
}
return sum / nValid
}
function evaluatePixel(samples) {
return [calculateAverage(samples.beforeEvent)]
}
When simply trying to get the metadata, I simply get an empty JSON file ({}
). When including the code to return the average of the beforeEvent
samples, I am getting this:
Server response: "{"error":{"status":400,"reason":"Bad Request","message":"Failed to evaluate script!\nevalscript.js:28: TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined\n for (let sample of samples) {\n ^\nTypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined\n at calculateAverage (evalscript.js:28:24)\n at evaluatePixel (evalscript.js:48:13)\n at executeForMultipleScenes (<anonymous>:1153:14)\n","code":"RENDERER_EXCEPTION"}}"
I am certainly missing something with the data structure of the samples
object and how to access them based on their identifiers. Would this kind of processing be possible without a data fusion request?