尊敬的Sentinel-2爱好者!
首先,我祝您圣诞快乐,节日快乐。我以为我将在家庭聚会之间的空闲时间首先用于消化美味的圣诞节饼干,其次用于撰写有关如何使用Python或命令行下载Sentinel-2卫星图像的简短文章。
为什么这有帮助?
嗯,这取决于您的应用程序,但是总的来说,它可以使您的程序/代码实现更高程度的自动化,因为您赢得了’不必登录到数据提供商的网站/门户(例如: scihub.copernicus.eu ),然后手动查找图像。从现在开始,您将能够直接从Python控制台或命令行下载最新的Sentinel-2图像,并希望能够安全地使用一些时间。“Th这个力量很强大!”
先决条件
在开始之前,我们需要安装名为“ 哨兵 “。那么我们如何得到它呢?它’s as easy as
pip install 哨兵
如果你不这样做’无法使用点子,请按照以下说明进行操作 的Linux 要么 苹果系统 .
让 ’s start
蟒蛇
In 要么 der to download Sentinel-2 imagery via 蟒蛇 , all we need is the function:download_safe_format
. Simply specify the tileID and the date you want to download as follows:
哨兵 .download_safe_format(tile=('T33UXP', '2017-05-01'))
瞧!所有乐队将下载到当前工作目录中。关于此功能的好处是数据在 。安全 执行sen2cor所需的格式。如果要下载图块的整个产品,请添加download_safe_format(..., entire_product=True).
命令行
从命令行来看,该功能的工作原理非常相似。您可以使用以下行获得相同的结果:
$ 哨兵 .aws --tile T33UXP 2017-05-01 -e
标志-e再次使我们能够下载与所选图块相对应的整个产品。
包起来
现在让’s说我们要从2017年5月开始下载两个图块的所有图像。上面的函数使这个相当容易吧?您可以使用以下方法:
#First import all needed modules import 哨兵 import pandas as pd import datetime #specify tiles, for example two in the eastern part of Austria: tiles = ["T33UXP","T33UVP"] #specify start and end date (here we use May 2017) dateStart = "2017-05-01" dateEnd = "2017-05-31" #create date range dates = pd.date_range(start=dateStart, end=dateEnd) #loop over tiles for tile in tiles: print("Downloading tile: " + tile) #loop over dates for date in dates: print(str(date.date()) + " ...") #try if there is a product available for the selected date try: 哨兵 .download_safe_format(tile=(tile, str(date.date())), entire_product=True) except Exception as ex: template = "No image for the specified tile / date combination could be found." message = template.format(type(ex).__name__) print(message)
希望对您有所帮助。如果您需要有关sentinelhub模块的更多信息,请查看 这里 或给我们留言。
马丁
4条留言
您可以在这篇文章中发表评论。
嗨,马丁!
我发现您的代码非常有帮助!我在2016年尝试将其用于S2,并且能够下载所有可用的.SAFE文件夹。但是现在我发现了一个问题..我无法使用SNAP打开这些文件。看来这些文件夹是空的。我究竟做错了什么?
劳拉 3年前
嘿劳拉,
自从发布此博客文章以来,该软件包进行了一些重大改进和更改。这可能会产生与预期不同的结果。
在此处查看有关如何以SAFE格式下载S2的新规范: http://sentinelhub-py.readthedocs.io/en/latest/examples/aws_request.html#Data-into-.SAFE-structure
马丁 3年前
非常感谢!
我将在工作中使用此脚本的一些改编。
胡安马 2年前
嗨,马林,
感谢您的分享。现在,我想下载无云S2数据。那么我应该如何修改您的脚本。您能给我一些建议吗?非常感谢。
冯高 2年前
发表回复