本节内容引用自:https://blog.csdn.net/lidahuilidahui/article/details/90486402#sentinelsat_83
使用IDM软件实现分段下载:详细教程
【官网下载】The Copernicus Open Access Hub哥白尼数据开放访问中心
【长期档案数据(LTA,Long Term Archive)】现阶段使用较少的历史数据会被离线(标记为"Offine"),不让下载,以减少服务器压力
【如何下载已被下线的数据?】
【使用SNAP软件批量下载】
【Vertex网站(美国阿拉斯加卫星设备处)】
【提供的数据】Sentinel-1、ALOS-1、Radarsat-1、ERS-1/2
【下载帮助文档】链接
【缺点】速度慢
【USGS(美国地质调查局网站)】
【Sentinelsat包介绍】
【相关链接】
【安装】pip install sentinelsat
【使用】
# -*- coding: utf-8 -*-
# @Time : 2019/8/14 15:53
# @Author : PasserQi
# @Email : [email protected]
# @File : download
# @Software: PyCharm
# @Version : v1.2.1
# @Desc : 批量下载哨兵数据
# 1. 下载在线数据--[OK] v1.0.0
# 2. 下载离线数据--[OK] v1.1.0
# 3. 多线程下载
# --[WARNING] v1.2.1 threading模块未起作用,需要看sentinelsat源代码
# 4. 分段下载
from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
from collections import OrderedDict
import threading
import os
# settings
output_dir = r"F:\下载" # 数据保存路径
query_excel_fn = "搜索结果.xls" # 查询结果
success_excel_fn = "success.xls" # 成功结果
aoi_geojson_fp = r"D:\mycode\GISandPython\2Sentinelsat\xiping.geojson" # 感兴趣区域的GeoJSON文件
query_kwargs = { # 查询的参数
"platformname" :'Sentinel-1',
"date" : ('20180101','20181231'),
"producttype" : 'SLC',
"sensoroperationalmode" : 'IW',
# "orbitnumber" : 16302,
# "relativeorbitnumber" : 130,
# "orbitdirection" : 'ASCENDING',
}
thread_num = 3 # 线程数
def products_to_excel(products, fp):
infos = {}
for item in products:
info = products[item]
for name in info:
value = info[name]
if name in infos:
infos[name].append(value)
else:
infos[name] = [
value
]
dict_to_excel(infos, fp)
def dict_to_excel(d, fp):
import pandas as pd
data = [d[key] for key in d]
df = pd.DataFrame(data=data).T
df.columns = d.keys()
df.to_excel(fp)
threads = []
def download_one(api, product, product_info):
# download
api.download(product, directory_path=output_dir)
# save info
success_products[product] = product_info
products_to_excel(success_products, success_excel_fp)
print('\t[SUCCESS] {}/{}'.format(len(success_products), total))
# del products[product] #删除 --> [ERROR] OrderedDict不允许改变
# print('\t[surplus] {}'.format(len(products) ))
# program variable
success_products = OrderedDict()
products = OrderedDict()
if __name__ == '__main__':
query_excel_fp = os.path.join(output_dir, query_excel_fn)
success_excel_fp = os.path.join(output_dir, success_excel_fn)
# 用户名,密码
api = SentinelAPI('账号', '密码')
# 搜索
footprint = geojson_to_wkt( read_geojson(aoi_geojson_fp)) # 读取geojson文件,获取足迹
kw = query_kwargs.copy() # 设置查询参数,足迹,平台,日期,产品类型,返回的是以产品id为key的复合字典
results = api.query(footprint, **kw)
products.update(results)
# ui
total = len(products)
print("[Total] {} ".format(total) )
# save file
products_to_excel(products, query_excel_fp)
# 先激活离线产品
try:
print("===触发离线产品上线===")
cnt = 1
for product in products:
product_odata = api.get_product_odata(product)
if not product_odata['Online']:
print("[激活离线产品 {}] {}".format(cnt, product_odata['date']))
api.download(product, output_dir) # 触发重新上线
cnt += 1
except:
print("[抱歉] 该账户激活离线产品的次数不足")
pass
# 开始下载
print("===开始下载===")
while len(success_products)!=total:
for product in products:
product_odata = api.get_product_odata(product)
if product_odata['Online']: #在线
# 打印产品文件名
print('[Online] {} {}'.format(product_odata['date'], product_odata['title']) )
# 下载
# print("线程数 {}".format(threading.active_count()) ) #debug
if threading.active_count()<=thread_num: #线程没有起作用
t = threading.Thread(download_one(api, product, products[product]) )
t.start()
else:
# 离线数据不下载,等待上线
print("[Offine] {}".format(product_odata['date'] ))
【10054】OpenSSL.SSL.SysCallError: (10054, ‘WSAECONNRESET’)
【Requests exceed user quota】sentinelsat.sentinel.SentinelAPILTAError: HTTP status 403 Forbidden: Requests for retrieval from LTA exceed user quota