如何堆叠哨兵乐队?

时间:2019-04-02 08:45:05

标签: python-3.x sentinel2 rsgislib

我处理许多Sentinel-2图像,我希望将其12条图像堆叠到一个文件中。我的图像采用envi格式(img和hdr)。

我尝试通过应用以下代码与rsgislib模块进行串联:

import rsgislib
from rsgislib import imageutils

imagePath = "/run/media/afavro/Elements/Acquisitions_Copernicus2/Sentinel-2/THEIA/2A/resampling/subset_20181005_944_J_resampled.data/"

nom = 'ROI_Resize__Layer__Band_1_SENTINEL2A_20181005_104840_944_L2A_T31TDJ_D_V1_9'
imageList = [nom + '_ATB_R1.hdr',
         nom + '_ATB_R2.hdr',
         nom +'_SRE_B2.hdr',
         nom +'_SRE_B3.hdr',
         nom +'_SRE_B4.hdr',
         nom +'_SRE_B5.hdr',
         nom +'_SRE_B6.hdr',
         nom +'_SRE_B7.hdr',
         nom +'_SRE_B8.hdr',
         nom +'_SRE_B8a.hdr',
         nom +'_SRE_B9.hdr',
         nom +'_SRE_B10.hdr',
         nom +'_SRE_B11.hdr',
         nom +'_SRE_B12.hdr',
         nom +'_FRE_B2.hdr',
         nom +'_FRE_B3.hdr', 
         nom +'_FRE_B4.hdr',
         nom +'_FRE_B5.hdr',
         nom +'_FRE_B6.hdr',
         nom +'_FRE_B7.hdr',
         nom +'_FRE_B8.hdr',
         nom +'_FRE_B8a.hdr',
         nom +'_FRE_B9.hdr',
         nom +'_FRE_B10.hdr',
         nom +'_FRE_B11.hdr',
         nom +'_FRE_B12.hdr']


bandNamesList = ['_ATB_R1',
             '_ATB_R2',
             '_SRE_B2',
             '_SRE_B3',
             '_SRE_B4',
             '_SRE_B5',
             '_SRE_B6',
             '_SRE_B7',
             '_SRE_B8',
             '_SRE_B8a',
             '_SRE_B9',
             '_SRE_B10',
             '_SRE_B11',
             '_SRE_B12',
             '_FRE_B2',
             '_FRE_B3', 
             '_FRE_B4',
             '_FRE_B5',
             '_FRE_B6',
             '_FRE_B7',
             '_FRE_B8',
             '_FRE_B8a',
             '_FRE_B9',
             '_FRE_B10',
             '_FRE_B11',
             '_FRE_B12']

# Output image
outputImage = 'SENTINEL2A_20181005-104840-944_L2A_T31TDH_D_V1-9_stack.envi'
# Format and type
gdalFormat = 'ENVI'
dataType = rsgislib.TYPE_16UINT
# Stack
imageutils.stackImageBands(imageList, bandNamesList, outputImage, None, 0, gdalFormat, dataType)

但是无论我更改什么参数,我总是会得到相同的错误消息:

"There are 26 images to stack
ROI_Resize__Layer__Band_1_SENTINEL2A_20181005_104840_944_L2A_T31TDJ_D_V1_9_ATB_R1.hdr
ERROR 4: ROI_Resize__Layer__Band_1_SENTINEL2A_20181005_104840_944_L2A_T31TDJ_D_V1_9_ATB_R1.hdr: no such files or folders

Traceback (most recent call last):

  File "<ipython-input-4-9b52a8bb11b5>", line 70, in <module>
    imageutils.stackImageBands(imageList, bandNamesList, outputImage, None, 0, gdalFormat, dataType)

error: Could not open image ROI_Resize__Layer__Band_1_SENTINEL2A_20181005_104840_944_L2A_T31TDJ_D_V1_9_ATB_R1.hdr" 

您对我有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您正在输入头文件。我相信您应该输入图片文件(例如,.envi,如果这是您使用的扩展名)。