<jupyter_start><jupyter_text>Third party Data Import - PlanetScope This Jupyter Notebook demonstrates how to import **PlanetScope** data into Sentinel Hub and then access it.We will use **Simple search** and **Order products**[1]. Useful links:      [1] TPDI API documentation: https://docs.sentinel-hub.com/api/latest//DATA_IMPORT_API/README      [2] TPDI API reference (Swagger docs): https://docs.sentinel-hub.com/api/latest/reference/tag/dataimport_planet      [3] About PlanetScope data: https://docs.sentinel-hub.com/api/latest//data/PlanetScope  Imports and credentials If you are running the JN localy fill in **config.py** file with your credentials. If you are running the JN on EDC, you will need a SH subscription and SH credentials will be automatically available.<jupyter_code># Read SH credentials from environment variables
import os

client_id = os.environ['SH_CLIENT_ID']
client_secret = os.environ['SH_CLIENT_SECRET']
import requests 
import json
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
import os
import datetime
import dateutil.parser

# Create a session
client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)


# Get token for the session
token = oauth.fetch_token(token_url='https://services.sentinel-hub.com/oauth/token',
                          client_id=client_id, client_secret=client_secret)
#Get my quota

url = f"https://services.sentinel-hub.com/dataimport/v1/quotas"

r = oauth.get(url=url)
r.json()<jupyter_output><empty_output><jupyter_text>Search<jupyter_code>url = "https://services.sentinel-hub.com/dataimport/v1/search"

aoi = {'type': 'Polygon',
  'coordinates': [[[12.560804463221928, 41.885177999999996],
    [12.585804463221926, 41.885177999999996],
    [12.585804463221926, 41.910178],
    [12.560804463221928, 41.910178],
    [12.560804463221928, 41.885177999999996]]]}

aoi = {"type": "Polygon", "coordinates": [[[12.567054463221927, 41.891428], [12.579554463221926, 41.891428], [12.579554463221926, 41.903928], [12.567054463221927, 41.903928], [12.567054463221927, 41.891428]]]}

query = {
    "provider": "PLANET",
    "planetApiKey": PLANET_API_KEY,
    "bounds": {
        "geometry": aoi
    },
    "data": [
        {
            "itemType": "PSScene4Band",
            "dataFilter": {
                "timeRange": {
                    "from": "2020-04-15T00:00:00.000Z",
                    "to": "2020-04-17T00:00:00.000Z"
                },
                "maxCloudCoverage": 30
            }
        }
    ]
}

response = oauth.post(url, json=query)
response.raise_for_status()

results = response.json()
search_results = [(feature["id"], feature["properties"]['acquired'], \
                   feature["properties"]['cloud_cover']) \
                   for feature in results["features"]]
print("Product id \t acquisition date&time \t cloudcover  ")
for item in search_results:
    print(item[0],   item[1],   item[2])
# Additional filtering of search results by cloud coverage
item_ids = [feature['id'] for feature in results["features"] if feature["properties"]['cloud_cover'] == 0]
item_ids<jupyter_output><empty_output><jupyter_text>Order data import<jupyter_code>url = "https://services.sentinel-hub.com/dataimport/v1/orders"

query['data'][0]["productBundle"] = "analytic"

name = "<NAME>"
payload = {
    "name": name,
    "input": query
}

response = oauth.post(url, json=payload)
response.raise_for_status()

order = response.json()
order_id = order['id']
area = order['sqkm']
print(f"Order {name}, id: {order_id}, area: {area} km^2")<jupyter_output>Order anja test, id: 109af2d3-b72e-4304-ba8c-a0d5d8f8dd96, area: 4.968239307460755 km^2<jupyter_text>Confirm the order<jupyter_code>url = f"https://services.sentinel-hub.com/dataimport/v1/orders/{order_id}/confirm"

response = oauth.post(url)
response.raise_for_status()
response.json()<jupyter_output><empty_output><jupyter_text>Check Status<jupyter_code>order_id = order_id

url = f"https://services.sentinel-hub.com/dataimport/v1/orders/{order_id}"

response = oauth.get(url)
response.raise_for_status()

order_status = response.json()
order_status<jupyter_output><empty_output><jupyter_text>List all orders<jupyter_code>url = "https://services.sentinel-hub.com/dataimport/v1/orders"

response = oauth.get(url)
response.raise_for_status()

response.json()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup