1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| from sentinelsat.sentinel import SentinelAPI from collections import OrderedDict
name='' password='' api = SentinelAPI(name,password, 'https://scihub.copernicus.eu/dhus/' xmin,ymin,xmax,ymax=120,34,121,35 roi="POLYGON(("+str(xmin)+" "+str(ymin)+","+str(xmax)+" "+str(ymin)+","+str(xmax)+" "+str(ymax)+","+str(xmin)+" "+str(ymax)+","+str(xmin)+" "+str(ymin)+"))"
start_date = '20190524' end_date = '20190530'
platformname='Sentinel-2'
product_type = 'S2MSI2A'
cloud_cover = (0, 50)
download_path="E:\\"
success_products = OrderedDict() products = OrderedDict()
results = api.query(area=roi,date=(start_date, end_date),platformname=platformname,producttype=product_type, cloudcoverpercentage=cloud_cover) products.update(results)
total = len(products) print(" {} data finded ".format(total))
def download_one(api, product, product_info): api.download(product, directory_path=download_path) success_products[product] = product_info print('\t[success:] {}/{}'.format(len(success_products), total))
try: print("---Trigger offline product---") cnt = 1 for product in products: product_odata = api.get_product_odata(product) if not product_odata['Online']: print("Trigger offline data {}: {}".format(cnt, product_odata['date'])) api.download(product, download_path) cnt += 1 except: print("Sorry, requests for retrieval from LTA exceed user quota (No more than 20 times)") pass
print("---Download Start---") while len(success_products)!=total: for product in products: product_odata = api.get_product_odata(product) if product_odata['Online']: print('Data online,can be downloaded:{} {}'.format(product_odata['date'], product_odata['title']) ) download_one(api, product, products[product]) else: print("[Data offline,please wait:] {}".format(product_odata['date'] ))
|