01-SNAP and snappy introduction and installation


(Original article, reproduced, please indicate the source, thank you!)

Foreword

This article "SNAP and snappy" column on a blog. Thanks to ESA (European Space Agency, ESA) support, at this stage we are able to use a lot of good free remote sensing satellite data (example: Sentinel-1, Sentinel-2 , Sentinel-3 , etc.), and Europe CSA independently developed open-source remote sensing data processing platform ----- SNAP these remote sensing data to adapt. SNAP open source software explained the "open world, freedom of science" that spirit, to bring the convenience of remote sensing related disciplines researchers, making remote sensing data processing and analysis to better carry out. In SNAP official forum in contact with the relevant ESA experts, they feel solid and profound spiritual knowledge and free and open, and feel in the forum, with relevant scientific research personnel and insufficient attention. In the domestic field of remote sensing processing software is more than ENVI, ERDAS, PCI, ArcGIS foreign monopoly remote sensing, many more remote sensing image colleges teach practical courses are operating the software, open source remote sensing software SNAP, QGIS and so little introduction, is not conducive to get rid of dependence on foreign countries. Create a "SNAP and snappy" column purposes, mainly in order to promote the use and development of open-source remote sensing SNAP processing software, learning its advanced processing technology and the underlying algorithms for future remote sensing to better serve the domestic service industry. Box behind the content will use open source software QGIS SNAP and other open source software introduction, less or even no any commercial software.

About SNAP

Used Sentinel series of remote sensing data relevant disciplines should contact the SNAP software, the Internet has introduced a number of articles, but regardless of the depth or breadth, far fail to reflect the advantages of SNAP where, in research to understand SNAP still belong to the circle of people few. Although ESA SNAP official website and so there are a lot of tutorial information on SNAP, but either because of language or because of lack of basic knowledge, caused some difficulties.

SNAP Introduction

STEP

ESA under SEOM project (the Scientific Exploitation of Operational Missions) to support the development of free, open-source toolkit for the earth science observation satellites (mainly Sentinel series of satellites). ESA will these open source toolkit on STEP (Scientific Toolbox Exploitation Platform) The ESA community platform for researchers to access, download and use the platform software and its documentation, and developers to communicate, within the scientific community dialogue, promote exchanges and improve outcomes, and provide tutorials and training materials for the use of scientific toolbox scientists.

SNAP

Most of the following from the know "Copernicus Program software support -SNAP" column of the image almost Sentinel , the article describes the relatively full (in fact, if you look at the official website visited SNAP words, the article mainly translation to the official website), and modified and supplemented in part. Most of the following from the know "Copernicus Program software support -SNAP" column of the image almost Sentinel , the article describes the relatively full (in fact, if you look at the official website visited SNAP words, the article mainly translation to the official website), and modified and supplemented in part.

ESA toolkit supports ERS-ENVISAT mission, the satellite data processing tasks and a series of national sentinel 1/2/3 and third-party missions. These three are called Sentinel 1,2 toolbox and 3 toolbox, they share a common architecture of a called SNAP.

SNAP's predecessor from the toolbox they contain some historical features in the past few years developed, such as BEAM , NEST (the Next Esa Sar Toolbox) and Orfeo Toolbox . If you look through some of the early articles of remote sensing, you should be able to see these software (Toolbox).

SNAP (Sentinel Application Platform) is the Sentinel data application platform, all sentinel toolbox basic platform (public infrastructure), CS end desktop platform. Scalability, portability and modular interface.

main feature:

  • All common architecture toolbox;
  • You can achieve Gigabit fast image display and navigation;
  • Graphics Processing Framework (GPF): processing for creating user-defined chain;
  • Advanced Layer Management: allows adding new operations and overlay, such as an image of the other bands, the WMS server or image from ESRI shapefile;
  • ROI is defined rich regions of interest, and a variety of statistical data in the figure;
  • And a simple calculation superposed band;
  • The use of flexible mathematical expressions;
  • Common map projection for accurate reprojection and orthorectified;
  • The use of ground control points geocoding and finishing;
  • SRTM DEM automatically download and selection;
  • Efficient scanned and indexed portfolio for large files;
  • Multi-threading and multi-core processor support;
  • Integrated Visualization WorldWind;

SNAP utilized to technology:
NetBeans Platform - Desktop Application Framework;
install4j - Multi-platform installation;
GeoTools - geospatial analysis tool library;
GDAL ; - raster, vector data read and write
Jira issue tracker -;
Git - version control in GitHub into the type of hosting

Sentinel Toolbox:

  1. Sentinel-1 Toolbox (S1TBX)
  • Inherits most of the features and expand NEST toolbox, primarily for processing SAR data: radiometric calibration process speckle, terrain correction, correction ellipsoid reprojection, registration, timing analysis, the Decomposition, classification, interference other treatment
  • Supported SAR satellite data: Sentinel-1, ERS-1 & 2, Envisat, ALOS PALSAR, TerraSAR-X, COSMO-SkyMed, RADARSAT-2 SAR data and other third party;
  1. Sentinel-2 Toolbox (S2TBX)
  • Mainly for processing multispectral data, including a mask, cropping, resampling, histogram, spectrum analysis, reprojection operation band, more exponential operator (e.g. NDVI, NDWI, LAI, CCC, etc.), and unsupervised supervised classification and many other operations
  • Support multispectral satellite data: Sentinel-2, Envisat (MERIS and AATSR), ERS (ATSR), RapidEye, SPOT, MODIS (Aqua and Terra), Landsat (TM), ALOS third-party data (AVNIR & PRISM) and the like;
  1. Sentinel-3 Toolbox (S3TBX)
  • Supports data visualization (raster pyramids, raster layer ink ribbon, etc.) is provided, analysis of data (cross-sectional view, scatter, correlation analysis), raster data processing (reprojection, mosaic, clustering, classification) process, etc.
  • Support Data Type: Sentinel-3 and the OLCI SLSTR, Envisat (MERIS and AATSR), ERS (ATSR), SMOS, MODIS (Aqua and Terra), Landsat (TM), ALOS (AVNIR &), PRISM and the like.
  1. SMOS Toolbox
  • User data support the use and handling of ESA (Soil Moisture and Ocean Salinity, SMOS) satellite acquired
  1. Proba-V Toolbox
  • Enables customers to address data Proba-V satellite-derived preparations (research and PROBA-V satellite is in the follow-up of 15 years SPOT-VEGETATION observation missions, but also to ESA Sentinel-3 land and ocean observation satellite mission recently launched the jobs.)
  1. PolSARPro : PolSARpro software made a number of famous Pol-SAR algorithms and tools, laid the foundation for scientific development and utilization of polarization measurement techniques, and the use of Pol-SAR, Pol-InSAR, Pol-TomoSAR and Pol-TimeSAR stimulate research and data applications development, contact PolSAR research should be more familiar.
  2. Third-party plug-ins
  • Sen2cor : L2A the Sentinel-2 format and product generation processor; it L1C stage atmospheric air input data, and terrain correction cirrus . Sen2Cor bottom create atmosphere, and optionally formed cirrus corrected reflected image; in addition, also creates AOD, water vapor, scene classification probability map and cloud and snow with mask image quality index properties. Output format of the same product and L1C Level User Product Format: JPEG 2000 format image, three different resolution, 60, 20 and 10 m. .
  • Sen2Three : a Sentienl-2 L3 level processor for correcting the time series image composition Sentinel-2 L2A atmospheric level image, Sen2Three time series to a certain geographical area (tiles) L2A level image is input by the input image before All the "bad" pixel scene then gradually replaced with "good" pixels, generate a composite output image can be achieved Sentinel-2 L2A processed data to the cloud .
  • Sen2Res : A Sentinel-2 product spatial resolution to 10m / pixel processor, the reflectance can be maintained products. Sentinel-2 MSI panchromatic not , but it contains four 10m / pixel band. Sen2Res working principle is to establish a model that describes how to share information between these bands (that is, independent of the reflectivity of the pixel content), as well as what information is specific to these bands (that is, the color of the pixel content). The model is then applied 20m / pixel band and 60m / pixel band is demodulated, while maintaining its reflectivity.
  • SNAPHU : Stanford University for the development of free InSAR phase unwrapping tool integration for Sentinel-1 IW SLC-class products InSAR phase unwrapping process in the SNAP.

to sum up

SNAP is actually a common architecture for all Sentinel SMOS toolbox and toolbox. SNAP This architecture is Earth observation satellite (Earth Oberservation Mission) data processing and analysis of the ideal architecture, it has the following technical innovations: scalability, portability, rich client platform modular, general purpose EO (Earth Oberservation) data abstraction model, the hierarchical memory management and graphics frame (Graph processing framework, gpt)

SNAP outstanding advantages:

  • Open Source (GPLv3 license), using a common framework to develop java
  • The original eco-series of Sentinel satellites Processing Platform
  • Graphics support frame (gpt) batch processing
  • Scalable java / Python source (Snappy) plug
  • Support engine and operate cloud platform
  • Cross-platform installed separately

National Remote Sensing related to our researchers, the main disadvantages are:

  • It does not support domestic processing satellite data;
  • Much of the information is in English;
  • Some operations may be imperfect, the operation is troublesome.

In a word, SNAP is an excellent open-source remote sensing processing software, it is worth learning and research.

SNAP installation

SNAP has been updated to version 7.0 , still using the old version of SNAP, the proposed upgrade it. In fact SNAP V8.0 has entered the development stage.

SNAP user Day Assembly ( SNAP the User Day ) will be held on September 10, 2019 : By then ESA SNAP development experts will attend the General Assembly, and to answer questions about the SNAP. Will share the hard core dry goods, interested, we must pay attention to.

SNAP v7.0 download site is: http://step.esa.int/main/download/snap-download/ . All Toolboxes recommended to choose the form of the installation package, eliminating the need for the rear portion of the insert cumbersome to install.
Here Insert Picture Description
SNAP installation is relatively simple.

Bloggers are currently using a Windows system, Windows system introduction at the following the following key steps.

Double-click the left mouse button to download esa-snap_all_windows-x64_7_0.exe (here is the .exe files in the Windows system) can be.
You can choose to install path:
Here Insert Picture Description
you can choose to install the toolkit, the default on the line.

Here Insert Picture Description
选择是否安装快捷方式及菜单目录,默认就行。
Here Insert Picture Description
如果你在安装SNAP前系统已经安装了Python(V2.7, V3.3-3.4版本)版本, 博主使用的Python 3.4.4版本,如果你没有安装Python的话,可以去掉小方框中的勾,暂不配置snappy文件,安装好SNAP后再snappy也是可以的。在安装了Python的前提下,在这一步可以直接配置snappy
Here Insert Picture Description安装配置后可以在C:\Users\XXXXX.snap\snap-python路径(XXXXXX代表的是用户名)下找到以下文件:
Here Insert Picture Description
后续是正常安装了,安装后在桌面上会生成SNAP的快捷方式。
Here Insert Picture Description
打开SNAP后如图所示:
Here Insert Picture Description

相关资源:

SNAP源码:https://github.com/senbox-org
SNAP官方论坛: https://forum.step.esa.int/
SNAP官方Wiki博客:https://senbox.atlassian.net/wiki/spaces/SNAP/overview
SNAP版本跟踪:https://senbox.atlassian.net/secure/Dashboard.jspa
SNAP Engine Java API文档:
http://step.esa.int/docs/v6.0/apidoc/engine/
SNAP Desktop Java API文档:http://step.esa.int/docs/v6.0/apidoc/desktop/

关于snappy

snappy简介

前面说到SNAP是使用Java源代码写的,必定是可以用Java编写程序进行开发的。不过,鉴于Python在目前开源世界中的数量庞大函数包和库,SNAP提供Python API接口模块snappy,以便充分利用大量Python的优质模块。

安装了snappy后,意味着你可以实现SNAP中的支持多种卫星数据(例如Sentinel-1, Sentinel-2等)处理的读写、处理、分析操作,并且可以借助Python第三方库(例如numpy, scipy,matplotlib, gdal, scikit-learn)快速实现各种自定义操作及高级算法,例如分割、面向对象分类,CNN分类等

snappy包也有两种类型,一种是Cpython(标准版Python),另一种是Jython。两种类型各有优缺点。见SNAP官方介绍:https://senbox.atlassian.net/wiki/spaces/SNAP/pages/19300362/How+to+use+the+SNAP+API+from+Python

CPython:

  • 如果您需要使用Python的科学扩展库,如numpy、scipy、matplotlib等;
  • 你已经有了CPython代码,你想要合并SNAP中的函数;
  • 您计划用Python实现一个快速数据处理器插件;
  • 您不打算开发SNAP桌面用户界面扩展;
  • 您不需要在所有平台上都具有完全的可移植性;
  • 您的代码依赖于(或将依赖于)许多非标准库。

如果你有以上需求,请安装标准Python (CPython)的snappy。

Jython:

  • 您计划开发SNAP桌面用户界面扩展;
  • 您需要在所有平台上都具有完全的可移植性;
  • 不需要像numpy等提供的强而有力的数组/栅格数据处理能力(因为Jython还不能很好地支持这些);

鉴于上述特点,毫无疑问选择CPython的snappy安装,因为我们要使用大量的第三方包(numpy, scipy, scikit-learn等),至于编写图形用户界面(GUI)有大量的第三方包(如PyQt)可以实现。

目前SNAP论坛绝大部分人安装的都是CPython类型的snappy,下面就Cpython类型的snappy的安装进行介绍(博主使用的是Win10系统)。

snappy安装

snappy的安装主要有两步:

  1. snappy包生成
  2. snappy包解译

snappy包生成

方法1----在安装SNAP直接生成:

见前面的SNAP安装教程,在SNAP安装过程直接配置,前提是你已经安装好了Python(v2.7, v3.3-3.4)。

看到这,你可能会问,能不能安装更高版本的Python(Python3.4以上版本),现在回答你这个问题,Python(v2.7, v3.3-3.4)这三个版本是欧空局推荐的版本,是经过欧空局官方测试的,最好使用这三个版本,另外,论坛也有使用Python3.5, 3.6安装成功的,但是不能保证里面是否有些代码使用是否会出错,至于更高版本Python3.7-3.8, 目前还没有人成功安装上,你可以自己试下。毫无疑问,欧空局后面会提升更高版本Python的支持,只是还需要一定的时间

博主的配置(或者说是建议吧)

不建议使用Python 2版本,这个版本在Python 官方会2020年停止维护。博主使用的两个版本的Python,分别是标准版Python 3.4.4(Python 3.4版本也已经失去支持了,但是Python3.4)以及Anaconda的Python3.6.7。使用Python 3.6,为了紧跟Python官方快速迭代更新的脚步,因为Python 3.4以下的版本有些库(例如gdal等库)已经失去支持了。另一方面,使用Python 3.4,是为了防止Python 3.6有些操作不支持。如无意外,博主后面将使用Python 3.6进行介绍。

  • 先说一下Python 3.4.4的问题:Python官网只提供了Python 3.4.5 -10版本的源码,需要自己编译(Python的源码是C语言编写的)才能安装,并且在Windows系统编译的话需要安装VS 2010(Visual Studio 2010),更高版本的VS好像编译通过不了。尽管编译不麻烦,但是VS安装包太大(安装后更是占用大量存储空间)了,我是肯定不会装的这样的庞然大物。因此,博主只好使用Python官网提供的编译好的最高版本的python 3.4.4,省去麻烦,见网址:
    https://www.python.org/downloads/release/python-344/
    点击该网址后往下拉,会看到编译好的MSI installer文件。下载后直接安装就行了。
    Here Insert Picture Description
  • 再说Python 3.6的安装:博主使用的是最新版的Anaconda,里面预装的是Python 3.7,需要建议一个Python 3.6的虚拟环境,这样的教程太多了,我不在复述了,随便粘贴一个教程:https://blog.csdn.net/Fhujinwu/article/details/85851587
  • Anaconda的spder, jupyter notebook等编辑器有时自动填充不够方便,还可以使用Pycharm作为IDE编辑器,Pycharm配置Python编译器网上有诸多教程,随便粘贴一个:https://blog.csdn.net/wingygrandam/article/details/79378286

方法二----利用SNAP的snappy-conf.bat脚本生成

在SNAP的安装路径(就是你配置安装的路径)下的snap/bin文件夹下可以看到一个snapp-conf.bat的脚本文件:
Here Insert Picture Description
(里面还有gpt命令行工具,利用gpt可以帮助snappy更好地处理代码,往后再介绍)

注意需在snappy-conf.bat脚本所在目录调用命令行(cmd)才可以直接使用下面命令,如果不是在snappy-conf前面加上绝对路径或者你将SNAP的bin文件路径添加到环境变量中

配置的命令如下:

snappy-conf <python-exe> <snappy-dir>

< p Y t h O n e x e > <python-exe> python解释器(python.exe文件)的绝对路径,注意,必须是绝对路径。
< s n a p p Y d i r > <snappy-dir> 为要放置生成的snappy包的目录路径,一般来说Python非标准库(第三方库)都放置在Python安装路径下Lib/dist-packages/目录下。这是一个可选参数。如果空缺的话将会生成在C:\Users\XXXXXX.snap\snap-python目录下(XXXXXX为用户名)。

Python 3.4为例:

博主的snappy-conf.bat文件所在绝对路径(见上图)为:
E:\SNAP\install_path\snap\bin\snappy-conf.bat

博主的使用的Python 3.4,python.exe文件所在的绝对路径为:
C:Python34\python.exe

Here Insert Picture Description
要放置的snappy包的绝对路径为:
C:\Python34\Lib\site-packages
Here Insert Picture Description
于是总的生成snappy包命令为:

E:\SNAP\install_path\snap\bin\snappy-conf.bat C:Python34\python.exe C:\Python34\Lib\site-packages

命令很长,可以新建一个.txt文件,写好命令再复制到命令行。博主很早就配置好了,没保留截图。贴一张官方的截图,注意路径需要修改为自己的:
Here Insert Picture Description
说下Anaconda的Python3.6:
如果是使用Anaconda虚拟环境安装Python3.6的话,在Anaconda的安装目录下会找envs这个文件夹,里面会有你装好的虚拟环境,例如楼主虚拟环境名称为py36,于是可以找到以下该目录:
Here Insert Picture Description
进入该目录后可以找到python.exe(解释器):
Here Insert Picture Description
该Python3.6虚拟环境的非准库也是在Lib\site-packages相对路径下:
Here Insert Picture Description
博主配置snappy是在snappy-conf.bat所在目录使用 Windows PowerShell(Win10命令行Shell,命令有点像linux系统csh(C Shell)命令,但又不全支持,有点鸡肋,不过也是可以执行.bat脚本的)配置的,如果你在win10当前目录启动PowerShell的话非常简单,例如博主在snappy-conf.bat目录下:
Here Insert Picture Description
鼠标移动左上方的文件菜单栏,可以看到:
Here Insert Picture Description鼠标左键单击一下即可打开,很方便,它的样子是这样的:
前面会提示当前路径
Here Insert Picture Description
配置snappy的命令如下:
运行.bat脚本文件或者.exe有时需要在前面添加".",否则可能会报错。成功后如下图所示
Here Insert Picture Description
同时可以到配置的路径下,看到下面的文件夹:
Here Insert Picture Description

snappy包解译

还差一步,需要对应的Python解释器解译snappy包的setup.py才能让Python解释器识别其为对应的模块库(这个工作通常可以借助pip命令完成,但这里不能)。注意,必须是对应的解释器,否则,可能安装错位置。不能用pip命令安装

解译命令为:

 <python-exe> setup.py install

< p Y t h O n e x e > <python-exe> 为对应的Python解释器,最好使用绝对路径。
setup.py 位于上一步生成的的snappy目录下

移动当前路径为上一步配置好的snappy文件夹所在的路径,会看到setup.py文件(你可能看到的文件少一些,因为这是解译成功后的文件夹),你会看到jpy包(Java-python bridge, Java-Python桥),这个非常重要的包。日后,你会看到snappy许多操作都会用到它。
Here Insert Picture Description
例如,博主使用的是Anaconda虚拟环境Python3.6,对应的解释器python.exe,所在完整路径为:E:\Anaconda\Anaconda3\envs\py36\python.exe。
因此,解译命令为:

E:\Anaconda\Anaconda3\envs\py36\python.exe setup.py install

成功解译后如下图所示
Here Insert Picture Description

snappy包测试

为了检查snappy是否安装成功可以用简单的小代码测试一下。
在生成的snappy下有一个testdata文件夹,会看到.dim格式的测试数据文件

Here Insert Picture Description
博主在Python 3.6环境下写的简单测试程序(注意,file_path为测试数据所在目录的完整绝对路径,当然你也可以使用Sentinel-1, Sentinel-2数据做测试):

from snappy import ProductIO
file_path = r'E:\Anaconda\Anaconda3\envs\py36\Lib\sitepackages\snappy\testdata\MER_FRS_L1B_SUBSET.dim'
p = ProductIO.readProduct(file_path)
list(p.getBandNames())
# print(list(p.getBandNames()))

成功后的结果如下图所示:

Here Insert Picture Description
如果你执行上述程序,没有报错,恭喜你成功安装上snappy。
关于snappy的入门级教程请看:
https://github.com/techforspace/sentinel

结语

SNAP与snappy的介绍、安装该收尾了,然而,SNAP的探索和开发之路才刚刚有了起点,漫漫长路伴你闯!还是提一句,如果你对SNAP或者snappy感兴趣的话,可以加入博主创建的欧空局SNAP处理交流QQ群:665903216。

参考文献

[1] STEP官网:http://step.esa.int/main/
[2] 知乎Sentinel影像专栏之《哥白尼计划的软件支持—SNAP》:https://zhuanlan.zhihu.com/p/61230869
[3] SNAP Wiki博客:https://senbox.atlassian.net/wiki/spaces/SNAP/pages/24051781/Using+SNAP+in+your+programs
[4] techforsapce官网:https://www.techforspace.com/

发布了11 篇原创文章 · 获赞 51 · 访问量 1万+

Guess you like

Origin blog.csdn.net/lidahuilidahui/article/details/99679554