4

I work with many Sentinel-2 images whose 12 strips I would like to stack into a single file. My images are in envi format (img and hdr).

I tried to do the concatenation with the module rsgislib by applying the following code :

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)

But whatever parameters I change, I always end up with the same error message :

"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" 

Do you have any advice for me ?

Ioannis Nasios
  • 8,292
  • 4
  • 33
  • 55
Axelle
  • 107
  • 1
  • 6

1 Answers1

1

You are inputting the header file. I believe you should be entering the image file (e.g., .envi if that is the extension you are using).