Skip to main content

Hello all, I have a question does Statistical api support data fuison request (custom script). If yes then could anyone please refer me to an example.

Thanks

Hi!


Thanks for the question, yes it is definitely possible to use data fusion in your Statistical API requests. Below is an example that uses Sentinel-1 GRD to as a dataMask to mask water pixels in an NDVI request derived from Sentinel-2 L2A.


evalscript = """
//VERSION=3
function setup() {
return {
input: [
// Sepcify input bands using the "id" of datasource set in the payload under data parameter
{datasource: "s2", bands: ["B04", "B08", "dataMask"]},
{datasource: "s1", bands: ["VV", "dataMask"]}
],
output: [
{
id: "ndvi",
bands: 1
},
{
id: "dataMask",
bands: 1
}],
mosaicking: "SIMPLE"
};
}

function evaluatePixel(samples) {
let ndvi = (samples.s2[0].B08 - samples.s2[0].B04) / (samples.s2[0].B08+samples.s2[0].B04);

// Create a mask for invalid ndvi value
let validNDVIMask = 1;
if (!isFinite(ndvi)) {
validNDVIMask = 0;
}

// Create a mask for water
let noWaterMask = 1;
if (toDB(samples.s1[0].VV) <= -20) {
noWaterMask = 0;
}
return {
ndvi: [ndvi],
// Combine all the masks
dataMask: [samples.s2[0].dataMask * samples.s1[0].dataMask * validNDVIMask * noWaterMask]
};
}

function toDB(input){
return 10 * Math.log(input)/Math.LN10;
}
"""

stats_request = {
"input": {
"bounds": {
"geometry": {
"type": "Polygon",
"coordinates": [
[
[16.72617,47.713689],
[16.72617,47.655444],
[16.816292,47.655444],
[16.816292,47.713689],
[16.72617,47.713689]
]
]
}
},
"data": [
{
"dataFilter": {},
"id": "s2",
"type": "sentinel-2-l2a"
},
{
"dataFilter": {
"resolution": "HIGH",
"acquisitionMode": "IW",
"polarization": "DV"
},
"processing": {
"backCoeff": "GAMMA0_TERRAIN",
"orthorectify": "true",
"demInstance": "MAPZEN",
"speckleFilter": {
"type": "LEE",
"windowSizeX": 5,
"windowSizeY": 5
}
},
"id": "s1",
"type": "sentinel-1-grd"
}
]
},
"aggregation": {
"timeRange": {
"from": "2021-08-01T00:00:00Z",
"to": "2021-08-31T23:59:59Z"
},
"aggregationInterval": {
"of": "P1D"
},
"resx": 0.00009,
"resy": 0.00009,
"evalscript": evalscript
},
"calculations": {
"default": {}
}
}

headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}

url = "https://services.sentinel-hub.com/api/v1/statistics"

response = oauth.request("POST", url=url, headers=headers, json=stats_request)
sh_statistics = response.json()
sh_statistics

These three cells can be used to generate and run this request. If you have any questions, then please let us know!


Hey, thanks for the reply. I wil look into this example.


Hello, hope you are doing well

I want to use specificallly this custom script. The aim is to identify the urban area of Dakar and the African Territories used in the custom script. Could you please guide me how can I obtain the desired results using statisitcal api.

Your help would be really appreciated.

Thanks


Reply