Data Fusion

Sentinel Hub (SH) allows you to combine the data from various data sources in the same request. To use this functionality you need to prepare a process API request with several data sources as explained below. Data fusion can be used for any data available in Sentinel Hub including PlanetScope, Pleiades, SPOT (TPDI) and your own data (BYOC).

Note: Using this functionality can consume more Processing Units since it processes more data. The rules listed here apply.

Preparing a Data Fusion Request

Preparing a data fusion request is very similar to preparing any process API request that uses a single data source. Thus, only the parts which differ when performing data fusion requests are described below.

Request Body

In the body of the request, more specifically in the input.data array, you need to add more than one collection. For each of these collection objects, you can specify the additional property:

  • "id" (optional) - a string defined by the user. It is used as an identifier for this collection so that it can be referred to in the evalscript. It is not mandatory to define it but we recommended to so, see examples below.

An example of the input.data object as part of a data fusion request:

{
"input": {
"data": [
{
"type": "S2L1C",
"id": "l1c",
"dataFilter": {
"timeRange": {
"from": "2018-10-01T00:00:00Z",
"to": "2018-11-01T00:00:00Z"
},
"mosaickingOrder": "leastRecent"
}
},
{
"type": "S2L2A",
"id: "l2a",
"dataFilter": {
"timeRange": {
"from": "2018-10-01T00:00:00Z",
"to": "2018-11-01T00:00:00Z"
},
"mosaickingOrder": "leastRecent"
}
}
]
}
}

As you can see in the example above all collection specific options are still available.

Evalscript

In the evalscript, under the input array in the setup function, where all data sources along with the bands that will be later used are specified, the following has to be added:

//VERSION=3
function setup() {
return {
input: [
{datasource: "l2a", bands:["SCL"], units: "DN"}],
{datasource: "l1c", bands:["B02", "B03", "B04"], units: "REFLECTANCE"}],
output: [
{id: "default", bands: 3, sampleType: SampleType.AUTO}
]
}
};

In the case you didn't specify the identifiers of each collection inside input.data array, the order of the data sources is relevant and should be the same as in the request body.

//VERSION=3
function setup() {
return ({
input: [
{bands:["B02", "B03", "B04"], units:"REFLECTANCE"}, // S2L1C
{bands:["SCL"], units: "DN"}], //S2L2A
output: [
{id: "default", bands: 3, sampleType: SampleType.AUTO}
]
})
};

After this, data from each collection can be accessed inside the evaluatePixel function as shown in the example below.

function evaluatePixel(samples) {
// "l1c" matches with the identifier defined in the body of the request.
var sample = samples.l1c[0];
let val = [sample.B04, sample.B03, sample.B02];
return {
default: val
}
}

If an identifier for each collection wasn't specified you can access the data with the default identifier '0' for the first data source, '1' for the next and so on.

function evaluatePixel(samples, inputData, inputMetadata, customData, outputMetadata) {
var sample = samples['0'][0]; // '0' is the identifier for the first collection specified on input.data array (S2L1C)
let val = [sample.B04, sample.B03, sample.B02];
return {
default: val
}
}

Examples

  • Data Fusion Examples

  • Additional examples can be found in the Request builder. Select PROCESS Mode and DATAFUSION datasource. This will load a prepared example and will allow you to play with Data Fusion in a more convenient way.