[Python] Sentinelsat模块 - 批量下载Sentinel数据 - 哨兵数据下载方法合集

[1]下载Sentinel数据的方法

本节内容引用自:https://blog.csdn.net/lidahuilidahui/article/details/90486402#sentinelsat_83

[☆]建议:使用IDM软件实现分段下载

使用IDM软件实现分段下载:详细教程

[1.1]哥白尼数据开放访问中心

【官网下载】The Copernicus Open Access Hub哥白尼数据开放访问中心

  • 官网说明
  • 【下载受限】购物车中的数据无法实现批量下载,每个账户同时最多只能下载2个产品数据
  • 【历史数据会被下线】使用较少的历史数据会被离线(即LTA)

【长期档案数据(LTA,Long Term Archive)】现阶段使用较少的历史数据会被离线(标记为"Offine"),不让下载,以减少服务器压力

【如何下载已被下线的数据?】

  • 强制下载离线产品,会触发它们重新上线
  • 24小时内必定重新上线,但具体时间不知道
  • 上线后,它们在网上至少保留3天

[1.2]SNAP软件批量下载

【使用SNAP软件批量下载】

  • 下载地址
  • 下载说明:请查看参考文章
  • 缺点:搜索下载通常比较费时,且不能下载被下线的历史数据

[1.3]Vertex(美国阿拉斯加卫星设备处)

Vertex网站(美国阿拉斯加卫星设备处)

  • 【提供的数据】Sentinel-1、ALOS-1、Radarsat-1、ERS-1/2

  • 【下载帮助文档】链接

  • 【缺点】速度慢

[1.4]USGS(美国地质调查局网站)

USGS(美国地质调查局网站)

  • 【提供的数据】Sentinel-2、Landsat、MODIS、DEM
  • 【下载帮助文档】链接
  • 【依赖】需要Java环境、Bulk Dowload Application(BDA)软件
  • 【缺点】下载流程复杂(从下订单、处理完成到下载,需要接收多个邮件),并且下载速度很慢

[2]Sentinelsat包

[2.1]介绍与安装

【Sentinelsat包介绍】

  • Sentinelsat包提供搜索、下载和检索Sentinel数据的功能
  • 数据来源:哥白尼数据开放访问中心

【相关链接】

【安装】pip install sentinelsat

[2.2]批量下载哨兵数据

【使用】

  1. 可以在官网中搜索出你想要的产品,然后记下你搜索时设置的参数
  2. 搜索的多边形需要用GeoJSON的形式进行组织(GeoJSON格式的多边形可以在这里获取
    • 以下例子:将GeoJSON格式搜索区域放到aoi_geojson_fp文件内
# -*- coding: utf-8 -*-
# @Time    : 2019/8/14 15:53
# @Author  : PasserQi
# @Email   : passerqi@gmail.com
# @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'] ))

[2.3]常见报错

【10054】OpenSSL.SSL.SysCallError: (10054, ‘WSAECONNRESET’)

  • 10054 对方已经关闭连接。

【Requests exceed user quota】sentinelsat.sentinel.SentinelAPILTAError: HTTP status 403 Forbidden: Requests for retrieval from LTA exceed user quota

  • 每个账户请求离线产品有限,一般20幅
  • 9
    点赞
  • 101
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

geodoer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值