Examples of Batch Processing 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.
A Postman collection with examples can be downloaded here.
Create a batch processing request
This request defines which data is requested and how it will be processed. In this particular example we will calculate maximum NDVI over two months period for an area in Corsica. To create a batch processing request replace <MyBucket>
with the name of your S3 bucket and run:
url = "https://services.sentinel-hub.com/api/v1/batch/process"evalscript = """//VERSION=3function setup() {return {input: [{bands: ["B04", "B08"]}],output: [{id: "default",bands: 3}],mosaicking: Mosaicking.ORBIT}}function calcNDVI(sample) {var denom = sample.B04 + sample.B08return ((denom != 0) ? (sample.B08 - sample.B04) / denom : 0.0)}const maxNDVIcolors = [[-0.2, 0xbfbfbf],[0, 0xebebeb],[0.1, 0xc8c682],[0.2, 0x91bf52],[0.4, 0x4f8a2e],[0.6, 0x0f540c]]const visualizer = new ColorRampVisualizer(maxNDVIcolors);function evaluatePixel(samples) {var max = 0for (var i = 0; i < samples.length; i++) {var ndvi = calcNDVI(samples[i])max = ndvi > max ? ndvi : max}ndvi = maxreturn visualizer.process(ndvi)}"""payload = {"processRequest": {"input": {"bounds": {"bbox": [8.44,41.31,9.66,43.1],"properties": {"crs": "http://www.opengis.net/def/crs/OGC/1.3/CRS84"}},"data": [{"dataFilter": {"timeRange": {"from": "2019-04-01T00:00:00Z","to": "2019-06-30T00:00:00Z"},"maxCloudCoverage": 70.0},"type": "S2L2A"}]},"output": {"responses": [{"identifier": "default","format": {"type": "image/tiff"}}]},"evalscript": evalscript},"tilingGrid": {"id": 0,"resolution": 60.0},"bucketName": "<MyBucket>","description": "Max NDVI over Corsica"}headers = {'Content-Type': 'application/json'}response = oauth.request("POST", url, headers=headers, json = payload)response.json()
Extracting the batch request id from the response:
batch_request_id = response.json()['id']
Get information about all your batch processing requests
url = f"https://services.sentinel-hub.com/api/v1/batch/process"response = oauth.request("GET", url)response.json()
Get information about a batch processing request
url = f"https://services.sentinel-hub.com/api/v1/batch/process/{batch_request_id}"response = oauth.request("GET", url)response.json()
Get current status of a batch processing request
url = f"https://services.sentinel-hub.com/api/v1/batch/process/{batch_request_id}"response = oauth.request("GET", url)response.json()['status']
Request detailed analysis (ANALYSE)
url = f"https://services.sentinel-hub.com/api/v1/batch/process/{batch_request_id}/analyse"response = oauth.request("POST", url)response.status_code
Get tiles for a batch processing request (optional)
url = f"https://services.sentinel-hub.com/api/v1/batch/process/{batch_request_id}/tiles"response = oauth.request("GET", url)response.json()
Request the start of processing (START)
url = f"https://services.sentinel-hub.com/api/v1/batch/process/{batch_request_id}/start"response = oauth.request("POST", url)response.status_code
Get the latest user's action for a batch processing request
url = f"https://services.sentinel-hub.com/api/v1/batch/process/{batch_request_id}"response = oauth.request("GET", url)response.json()['userAction']
Cancel a batch processing request (CANCEL)
url = f"https://services.sentinel-hub.com/api/v1/batch/process/{batch_request_id}/cancel"response = oauth.request("POST", url)response.status_code