Examples of Planetary Variables Import
Follow these examples to subscribe to and use Planetary Variables. To execute the requests you need to create an OAuth client as is explained here. It is named oauth in these examples.
Subscribe to Planetary Variables
The examples below use the Soil Water Content type and SWC-AMSR2-C_V1.0_100 ID. All Planetary Variable types and IDs can be used in these attributes.
Create Subscription
url = "https://services.sentinel-hub.com/api/v1/dataimport/subscriptions"payload = {"name": "My Soil Water Content subscription",# collectionId is optional. Remove it to create a new collection."collectionId": "<your Planet collectionId>","input": {"provider": "PLANET","planetApiKey": "...","bounds": {"geometry": {"type":"Polygon","coordinates":[[[14.500374,46.061428],[14.490287,46.050214],[14.492878,46.032905],[14.515692,46.029654],[14.52734,46.043557],[14.500374,46.061428]]]}},"data": [{"dataFilter": {"timeRange": {"from": "2023-06-01T00:00:00Z","to": "2023-06-30T23:59:59Z"}},"type": "soil_water_content","id": "SWC-AMSR2-C_V1.0_100"}]}}response = oauth.post(url, json=payload)response.raise_for_status()subscription = response.json()
To extract the subscription id from the response:
subscription_id = subscription['id']
Confirm the subscription
To initiate import, confirm the subscription:
url = f"https://services.sentinel-hub.com/api/v1/dataimport/subscriptions/{subscription_id}/confirm"response = oauth.post(url)response.raise_for_status()
Get subscription information
url = f"https://services.sentinel-hub.com/api/v1/dataimport/subscriptions/{subscription_id}"response = oauth.get(url)response.raise_for_status()subscription = response.json()
To extract the subscription status:
status = subscription['status']
To extract the BYOC collection ID:
collection_id = subscription['collectionId']
List subscription deliveries
To list the deliveries created so far for the subscription:
url = f"https://services.sentinel-hub.com/api/v1/dataimport/subscriptions/{subscription_id}/deliveries"response = oauth.get(url)response.raise_for_status()deliveries = response.json()
List all your subscriptions
url = "https://services.sentinel-hub.com/api/v1/dataimport/subscriptions"response = oauth.get(url)response.raise_for_status()response.json()
Visualize Soil Water Content and Extract Values
This is an example on how to visualize Soil Water Content PV to map and inspect the statistics features to assist with configuring visualizations in EOBrowser. For the Soil Water Content, you can base your visualization on the following evalscript:
//VERSION=3const vmin = 0const vmax = 0.4function setup() {return {input: ["SWC", "dataMask"],output: { bands: 4, sampleTYPE: "AUTO" },};}function updateColormap(vmin, vmax) {const numIntervals = cmap.lengthconst intervalLength = (vmax - vmin) / (numIntervals - 1);for (let i = 0; i < numIntervals; i++) {cmap[i][0] = vmin + intervalLength * i}}const cmap = [[0.00, 0xfff7ea],[0.05, 0xfaedda],[0.10, 0xede4cb],[0.15, 0xdedcbd],[0.20, 0xced3af],[0.25, 0xbdcba3],[0.30, 0xaac398],[0.35, 0x96bc90],[0.40, 0x80b48a],[0.45, 0x68ac86],[0.50, 0x4da484],[0.55, 0x269c83],[0.60, 0x009383],[0.65, 0x008a85],[0.70, 0x008186],[0.75, 0x007788],[0.80, 0x006d8a],[0.85, 0x00618c],[0.90, 0x00558d],[0.95, 0x00478f],[1.00, 0x003492],];updateColormap(vmin, vmax);const visualizer = new ColorRampVisualizer(cmap);function evaluatePixel(sample) {let scaleFactor = 1000let val = sample.SWC / scaleFactor;let imgVals = visualizer.process(val);return [...imgVals, sample.dataMask];}