Examples of Batch Statistical Workflow
The requests below are written in Python. To execute them, you need to create an OAuth client as is explained here. It is named oauth in these examples.
Create a Batch Statistical Request
This request defines which data is requested and how it will be processed.
In this example, we will receive the statistics for a single band on a given day.
To create a batch statistical request, replace the input.features.s3.url field with the actual path to the GeoPackage features, and the output.s3.url field with the desired path where the output data will be processed.
- Python SDK
evalscript = """
//VERSION=3
function setup() {
return {
input: [{
bands: [
"B04",
"dataMask"
]
}],
output: [
{
id: "output_B04",
bands: 1,
sampleType: "FLOAT32"
},
{
id: "dataMask",
bands: 1
}]
}
}
function evaluatePixel(samples) {
return {
output_B04: [samples.B04],
dataMask: [samples.dataMask]
}
}
"""
request_payload = {
"input": {
"features":{
"s3": {
"url": "s3://<my-bucket>/<path-to-geopackage>",
"accessKey": "<my-s3-access-key>,
"secretAccessKey": "<my-secret-access-key>
}
},
"data": [
{
"type": "sentinel-2-l2a",
"dataFilter": {
"mosaickingOrder": "leastCC"
}
}
]
},
"aggregation": {
"timeRange": {
"from": "2020-06-01T00:00:00Z",
"to": "2020-07-31T00:00:00Z"
},
"aggregationInterval": {
"of": "P30D"
},
"evalscript": evalscript,
"resx": 10,
"resy": 10
},
"output": {
"s3": {
"url": "s3://<my-bucket>/<path>",
"accessKey": "<my-s3-access-key>,
"secretAccessKey": "<my-secret-access-key>
}
}
}
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
url = "https://services.sentinel-hub.com/api/v1/statistics/batch"
response = oauth.request("POST", url=url, headers=headers, json=request_payload)
request_id = response.json()['id']
Note that in the above example, we are specifying an accessKey and secretAccessKey, so we can read and write to the user's bucket.
You can find more details about this under the AWS access section.
Get Information About a Batch Statistical Request
- Python SDK
response = oauth.request("GET", f"https://services.sentinel-hub.com/api/v1/statistics/batch/{request_id}")
response.json()
Get Status Information About a Batch Statistical Request
- Python SDK
response = oauth.request("GET", f"https://services.sentinel-hub.com/api/v1/statistics/batch/{request_id}/status")
response.json()
Request Analysis of a Batch Statistical Request (ANALYSIS)
- Python SDK
response = oauth.request("POST", f"https://services.sentinel-hub.com/api/v1/statistics/batch/{request_id}/analyse")
response.status_code
Request the Start of a Batch Statistical Request (START)
- Python SDK
response = oauth.request("POST", f"https://services.sentinel-hub.com/api/v1/statistics/batch/{request_id}/start")
response.status_code
Stop a Batch Statistical Request (STOP)
- Python SDK
response = oauth.request("POST", f"https://services.sentinel-hub.com/api/v1/statistics/batch/{request_id}/stop")
response.status_code