本文主要记录利用sentinelsat包批量下载sentinel2数据。
转载:https://blog.csdn.net/mrzhy1/article/details/107044828

方法一:直接利用sentinelsat包
1.sentinelsat包介绍
Sentinelsat提供了一个Python API和一个命令行接口,用于搜索、下载和检索Sentinel产品的元数据。如果是online数据,使用download函数就可以直接下载;如果是offline数据,download函数会对该数据进行激活。

GitHub:https://github.com/sentinelsat/sentinelsat
官方文档:https://sentinelsat.readthedocs.io/en/stable/
PyPi sentinelsat网址:https://pypi.org/project/sentinelsat/

2.sentinelsat包安装pip install sentinelsat
https://sentinelsat.readthedocs.io/en/stable/install.html

表示安装成功。
3.批量下载sentinel3 数据
(1)获取感兴趣区域对应范围的geojson文件:http://geojson.io

导出保存为GeoJSON格式:

下载sentinel2代码:

from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt
from datetime import date# connect to the API
api = SentinelAPI('user', 'password', 'https://apihub.copernicus.eu/apihub')# download single scene by known product id
api.download(<product_id>)# search by polygon, time, and Hub query keywords
footprint = geojson_to_wkt(read_geojson('map.geojson'))
products = api.query(footprint,date = ('20151219', date(2015, 12, 29)),platformname = 'Sentinel-2',cloudcoverpercentage = (0, 30))# download all results from the search
api.download_all(products)# GeoJSON FeatureCollection containing footprints and metadata of the scenes
api.to_geojson(products)# GeoPandas GeoDataFrame with the metadata of the scenes and the footprints as geometries
api.to_geodataframe(products)# Get basic information about the product: its title, file size, MD5 sum, date, footprint and
# its download url
api.get_product_odata(<product_id>)# Get the product's full metadata available on the server
api.get_product_odata(<product_id>, full=True)

代码来源:Github项目代码

或来自https://blog.csdn.net/lidahuilidahui/article/details/90486402的代码:

#sentinelsat中导入相关的模块
from sentinelsat import SentinelAPI, read_geojson, geojson_to_wkt#创建SentinelAPI,请使用哥白尼数据开放获取中心自己的用户名及密码
api =SentinelAPI(‘用户名', ‘密码','https://scihub.copernicus.eu/apihub/')#读入上海市的geojson文件并转换为wkt格式的文件对象,相当于足迹
footprint =geojson_to_wkt(read_geojson('map.geojson'))#通过设置OpenSearch API查询参数筛选符合条件的所有Sentinel-2 L2A级数据
products =api.query(footprint,                        #Area范围date=('20190510','20190512'),  #搜索的日期范围platformname='Sentinel-2',        #卫星平台名,Sentinel-2                    producttype='S2MSI2A',            #产品数据等级,‘S2MSI2A’表示S2-L2A级产品cloudcoverpercentage=(0,30))   # 云量百分比#通过for循环遍历并打印、下载出搜索到的产品文件名
for product in products:#通过OData API获取单一产品数据的主要元数据信息product_info = api.get_product_odata(product)#打印下载的产品数据文件名      print(product_info['title'])#下载产品id为product的产品数据api.download(product)原文链接:https://blog.csdn.net/lidahuilidahui/article/details/90486402

注意:sentinelAPI的使用方法

class sentinelsat.SentinelAPI(user, password,
api_url=‘https://scihub.copernicus.eu/apihub/’, show_progressbars=True,
timeout=None)

注意:这里api_url虽然给出了两个URL,但建议使用后者,即 https://scihub.copernicus.eu/dhus ,因为前一个URL:https://scihub.copernicus.eu/apihub ,无法下载历史数据,即使在历史数据由“Offline”变为“Online”时,也无法下载。但 https://scihub.copernicus.eu/dhus , 在历史数据由“Offline”变为“Online”时,可以恢复下载。其中一个URL下载速度慢时,也可以换另一个。
转自:https://blog.csdn.net/lidahuilidahui/article/details/90486402

使用https://scihub.copernicus.eu/dhus 可以下载历史数据,历史数据通过激活offline到online,实现下载。

方法二:利用IDM + sentinelsat(避免上面方法出现网断重新下载等问题)
参考如何使用sentinelsat包和IDM批量下载offline的sentinel数据:
下面记录自己操作的过程,及遇到的问题。

1.下载IDM
IDM下载(试用30天):https://www.internetdownloadmanager.com/

2.批量获取哥白尼数据开放访问中心购物车里的数据下载链接
(1)根据条件筛选数据:
打开哥白尼数据官网:https://scihub.copernicus.eu/dhus/#/home,根据传感器类型、时间、区域、云量等信息设定检索条件,然后利用爬虫提取产品链接:可以看这篇博主的文章:https://blog.csdn.net/mrzhy1/article/details/107019960

(2)利用Python爬虫技术提取数据标签
因为我这里是将检索的数据全部下载下来,不用经过再次筛选,所以不需要加入购物车,直接保存检索到的页面到本地,然后利用爬虫技术提取数据的标签。
1)保存页面到本地;
2)Python爬虫获取数据链接号和ID:
查看网页中数据链接所在的节点:

爬虫代码:(下载所有数据,非cart数据)

from bs4 import BeautifulSoup
import pandas as pd
import requestsfilepath='scihub.copernicus.eu.html'
with open(filepath,'rb') as f:ss=f.read()soup=BeautifulSoup(ss,'html.parser')
#获取所有class为list - link selectable的div标签下的a标签
divfind=soup.find_all('div',class_ = 'list-link selectable')
linklist=[]
idlist=[]
for df in divfind:#获取满足条件的div下的a标签#提取a标签的内容,即为数据链接link=df.find('a').stringid=link.split('\'')[1]linklist.append(link)idlist.append(id)linkdataframe=pd.DataFrame(linklist)
iddataframe=pd.DataFrame(idlist)#将数据链接写出
with pd.ExcelWriter('Httpandid.xlsx') as hifile:linkdataframe.to_excel(hifile,sheet_name='HTTP',header=False,index=False)iddataframe.to_excel(hifile,sheet_name='ID',header=False,index=False)

爬虫代码:(下载cart中的数据)

from bs4 import BeautifulSoup
import pandas as pd
import requestsfilepath='scihub.copernicus.eu.html'
with open(filepath,'rb') as f:ss=f.read()soup=BeautifulSoup(ss,'html.parser')
#获取所有id为cart-row-attributes的div标签
divfind=soup.find_all('div',id='cart-row-attributes')
linklist=[]
idlist=[]
for df in divfind:#获取满足条件的div下的a标签#提取a标签的内容,即为数据链接link=df.find('a').stringid=link.split('\'')[1]linklist.append(link)idlist.append(id)linkdataframe=pd.DataFrame(linklist)
iddataframe=pd.DataFrame(idlist)#将数据链接写出
with pd.ExcelWriter('Httpandid.xlsx') as hifile:linkdataframe.to_excel(hifile,sheet_name='HTTP',header=False,index=False)iddataframe.to_excel(hifile,sheet_name='ID',header=False,index=False)

代码来源:https://blog.csdn.net/mrzhy1/article/details/107019960

但是这种方法只能下载本网页显示的个数,比如显示150个,那么下载的链接也是150个,无法将所有的数据链接进行下载。

爬虫技术中重要包:

BeautifulSoup:是Python的一个HTML或XML的解析库,可以用它来方便地从网页中提取数据。
使用方法:BeautifulSoup(markup, “html.parser”)解析器为html.parser。

3.利用IDM下载sentinel3数据步骤
(1)打开IDM,下载——选项——站点管理,点击新建,添加路径(修改https,并添加scihub.copernicus.eu)、用户名和密码。

(2)设置IDM下载的属性:IDM支持对同一下载资源进行多连接下载,也能够同时下载多个资源。为了保护哨兵数据下载账号并正常下载数据,需要对IDM进行限制(设置为1),具体操作步骤:打开下载——选项——连接——新建,对话框输入网址https://scihub.copernicus.eu,最大连接数设为1。


(3)新建队列,命名为sentinel3
(4)数据批量下载
这里为了测试,先下载1个数据,将下载链接复制到txt文件中。全部选中数据,复制。

在IDM中,选择任务——从剪切板中批量下载

(注意需要科学上网才可以下载!)

如果出现显示超时,连接不上,在IDM中选择:选项——代理服务器——使用系统设置——确定,才可以下载数据。

4.IDM+sentinelsat结合批量下载sentinel3数据
思路:
(1)获取需要下载数据的链接和ID号;
(2)判断列表中第一个数据是online还是offline;
(3)如果是online数据,那就将数据链接添加到IDM的下载列表中,并进行下一次循环。
(4)如果是offline数据,那就使用download()函数对数据进行激活。并把该数据从列表的第一个位置删除,放在列表的最后一个位置。

这里直接利用使用sentinelsat包和IDM批量下载offline的sentinel数据的代码:

from subprocess import call
from sentinelsat import SentinelAPI
from datetime import date
import time
import xlrd
from tqdm import tqdmIDM = "IDMan.exe" #你电脑中IDM的位置
DownPath='F:/Sentinel_offline/' #数据要下载的地址api = SentinelAPI('ESA账号的账户名', '账号密码', 'https://scihub.copernicus.eu/dhus')#用于读取数据的HTTP链接到列表中
filepath='HTTPandID.xlsx'
workbook = xlrd.open_workbook(filepath)
sheet1 = workbook.sheet_by_name('HTTP')
linklist=sheet1.col_values(0)
#开始下载
print('开始任务:..................')
n=0
while linklist:print('---------------------------------------------------')n=n+1print('\n')print('第'+str(n)+'次循环'+'\n\n')id=linklist[0].split('\'')[1]link=linklist[0]product_info=api.get_product_odata(id)print('检查当列表里的第一个数据:')print('数据ID为:'+id)print('数据文件名为:'+product_info['title']+'\n')if product_info['Online']:print(product_info['title']+'为:online产品')print('加入IDM下载: '+link)call([IDM, '/d',link, '/p',DownPath,'/n','/a'])linklist.remove(link)call([IDM,'/s'])else:print(product_info['title']+'为:offline产品')print('去激活它')api.download(id)     #去激活它print('检查任务列表里是否存在online产品: .........')#等待激活成功的时候,检查现在的列表里还有没有online产品#如果有online的产品那就下载#首先检查列表中是否需要下载的数据if len(linklist)>1:#记录列表里可以下载的链接,并在最后把它们删除ilist=[]#开始寻找列表剩下的元素是否有online产品for i in range(1,len(linklist)):id2=linklist[i].split('\'')[1]link2=linklist[i]product_info2=api.get_product_odata(id2)if product_info2['Online']:print(product_info2['title']+'为在线产品')print('ID号为:'+id2)print('加入IDM下载: '+link2)print('--------------------------------------------')call([IDM, '/d',link2, '/p',DownPath,'/n','/a'])#在列表中加入需要删除产品的HTTP链接信息#直接在linklist中删除会linklist的长度会发生改变,最终造成i的值超过linklist的长度ilist.append(link2)else:continue#把已经下载的数据的链接给删除掉if len(ilist)>0:call([IDM,'/s'])for il in ilist:linklist.remove(il)print('本轮次检查结束,开始等到40分钟')#将该激活的产品删除,再加入到最后linklist.remove(link)linklist.append(link)#两次激活offline数据的间隔要大于30分钟for i in tqdm(range(int(1200)),ncols=100):time.sleep(2)

报错:
1)问题1

利用anaconda安装的sentinelsat,在Spyder中无法正常使用,直接打开spyder,在命令窗口中直接安装,可以解决这个问题。

2)问题2

对输入的文件进行格式转换,即xlsx转xls。

参考资料:
Sentinelsat模块 - 批量下载Sentinel数据 - 哨兵数据下载方法合集:https://blog.csdn.net/summer_dew/article/details/99649878

Python中使用sentinelsat包自动下载Sentinel系列数据:https://blog.csdn.net/lidahuilidahui/article/details/90486402#sentinelsat_83

sentinel3数据批量下载——sentinelsat相关推荐

  1. 大数据批量下载文件 代码

    大数据批量下载文件 代码 # # 大数据批量下载文件 from multiprocessing import Process import os import pandas as pd import ...

  2. Harvard Dataverse 数据批量下载

    最近看论文,看到了自己需要的数据,就想着下载下来,结果发现这个东西并不好下载,也可能是自己的知识存储不够,捣鼓了一天,终于下载下来了.这里记录一下,方便以后查阅. Harvard Dataverse ...

  3. 天文数据批量下载笔记

    数据批量下载笔记 一.astroquery 很多大型巡天项目都提供了下载数据的API方法,因此利用python脚本批量下载数据成为可能.基于已有的API(或者SQL)方法,astroquery整合了多 ...

  4. ECMWF等大气数据批量下载(Python API)详细步骤

    ECMWF等大气数据批量下载(Python API) 遥感方向做热红外温度反演,不可避免的要用到大气廓线数据,大气数据具有实时性,比如2018年9月1日的早上8点的影像,为了提高反演精度就需要用到时间 ...

  5. GPM数据批量下载教程

    GPM数据批量下载教程 1. GPM数据产品简介 2 查找数据 3. 下载 3.1. 授权 3.1.1 通过 `.netrc` 文件授权 3.1.2 *通过浏览器授权(通过 `.netrc` 文件授权 ...

  6. MODIS冰雪数据批量下载

    MODIS冰雪数据批量下载之Python Script 相信有很多的朋友在研究极地(南北两极)的冰雪吧,下数据可能对于某些大小同行来说是一个头疼的问题,本文在这里就介绍一种批量爬取数据的方法. 数据下 ...

  7. Sentinel-2 (哨兵2号) 数据批量下载教程 [python]

    Sentinel-2 [哨兵2号] 数据批量下载教程 [python] 1. 选择数据 2. 数据下载 2.1 下载链接文件 2.2 安装Python及data_downloader包 2.3 创建. ...

  8. 1、EC气象数据批量下载

    EC气象数据批量下载 前言 一.前期准备 1. 配置Python环境 2. 安装依赖库: 3. 注册EC账户并获得Key 3.1 注册账户 3.2 获取API信息 4. 选择数据 二.编写脚本开始下载 ...

  9. 使用Google Earth Engine (GEE)实现MODIS数据批量下载

    使用Google Earth Engine GEE实现MODIS数据批量下载 前言 下载数据代码 批量执行run任务 关注公众号,分享GIS知识.ArcGIS教程.SCI论文与科研日常等 前言 上图是 ...

  10. 基于官方API实现ESA遥感数据批量下载的方法

    一.确定Sentinel-2影像瓦片Tile分区号 Sentinel-2 A/B卫星的观测范围在56°S-84°N之间,影像数据采用UTM系统分区编码规则.其中,每个100km×100km的瓦片(Ti ...

最新文章

  1. iOS App上架流程
  2. IBM---Java 多线程与并发编程专题
  3. python可以给excel编程吗_python – 我可以通过编程方式将matplotlib图形插入Excel吗?...
  4. STL之map中排序方式的重载
  5. 毕业的那天,程序员师兄竟然让我去做这一行
  6. 摩托罗拉ex232java_摩托罗拉ex232r如何刷机?摩托罗拉ex232r评测
  7. js中的四舍五入函数
  8. angular开发中对请求数据层的封装
  9. 模糊PID控制在自动光电整纬装置中的应用
  10. java horizontalbarchart_Android-MPChart,HorizontalBarChart 水平柱状图颜色渐变
  11. 第九篇 设计模式之装饰模式
  12. 图片验证,滑块验证解决
  13. 51单片机教室人数进出统计检测数码管显示装置红外传感器
  14. YAMLException: bad indentation of a mapping entry at line 解决
  15. 【树莓派】树莓派3B+搭建Ubuntu
  16. 高端知识星球正式开放了
  17. 微信小程序审核不通过的原因,这里整理了10个最常见的
  18. 如何使用JavaScript导入和导出Excel文件
  19. CF711C三维DP
  20. 阿里云服务器cpu连续n天使用率为100%问题解决方案!

热门文章

  1. oracle分区索引优化,SQL优化思路结果集重用优化、分区索引优化测试
  2. HTML:实现旋转地球特效
  3. 用 RSocket 解决响应式服务之间的通讯
  4. @Resource 注解和 @Autowired 注解的对比
  5. 深度学习笔记_搭建一个简单网络(完整版)_手写数字识别MNIST
  6. C++_你真的知道++i 和 i++的区别吗?_左值/右值/右值引用
  7. python c++ socket 通信一个示例
  8. opencv图像分析与处理(12)-逆滤波、维纳滤波、约束最小二乘方滤波和几何均值滤波
  9. 数值分析(2)-多项式插值: 拉格朗日插值法
  10. cartographer的一些结果