0

This is probably a trivial question, but is it possible to create band composites using bands of different resolutions (10m, and 20m)? I tried that and exported the resulting rasters to JPEG and it looks like it worked... But I still can't wrap my head around it! edit: I haven't performed any kind of resampling prior to that. Here are the code snippets:

## Short-Wave Infrared (B12, B8A, B4)

eopatch=EOPatch.load('./Interpolated_NORM/eopatch_24')

bands=[]

for i in range (len(eopatch.timestamp)):
  dt=eopatch.timestamp[i]
  date=datetime.datetime(dt.year,dt.month,dt.day)     
  dates = np.array(eopatch.timestamp)
  closest_date_id = np.argsort(abs(date-dates))[0]
  
  dt=dates[closest_date_id]
  timestampStr = dt.strftime("%d-%b-%Y")

  #Extracting bands
  SWIR=eopatch.data['BANDS'][closest_date_id][..., [11]].squeeze()
  NIR=eopatch.data['BANDS'][closest_date_id][..., [8]].squeeze()
  RED=eopatch.data['BANDS'][closest_date_id][..., [3]].squeeze()

  #Stacking the bands
  bands=[SWIR, NIR, RED]
  SWIR_NIR_R=np.stack(bands, axis=2)
  pil_img = Image.fromarray((SWIR_NIR_R * 255).astype(np.uint8))

  #Saving the image
  img_name=timestampStr+'_'+'SWIR_NIR_R_24.jpeg'
  pil_img.save('./Exported_images/Short-Wave Infrared/eopatch_24/'+img_name)

I am not using any software, I am solely using python.

1 Answer 1

1

In a band composite, all layers need to match in terms of cell size, which is important e.g. for GeoTIFF. If you successfully stored your Sentinel-2 bands in one raster image, I assume the software performed a spatial resampling using the highest resolution (10m) for all layers.

What software like SNAP does is that it reads each layer one by one and handles the display internally. It is thus just a matter of visualisation. As soon as you perform actual pixel algebra, you will be asked to do the resampling first, which will store the original information in the .BEAM format.

Commercial software like Erdas Imagine does this in a very similar manner. It displays the bands with individual spatial resolution but when you save it to single file (.img) it performs a resampling.

5
  • The thing is I used only python and I just stacked the bands of different resolutions and exported them to JPEG. I didn't perform resampling or anything else prior to that. I added the code snippets as an edit.
    – Rim Sleimi
    Jul 8, 2020 at 10:05
  • The critical part is when you do np.stack. It will throw an error when the dimensions do not match. This leads me to believe that at that time the images are already harmonized in terms of spatial resolution. Maybe it is done in EOPatch.load I don't know about that module... Jul 8, 2020 at 11:34
  • I understand. I think this might have to do with the command line I used to download the data. I might have specified the resolution at the time.
    – Rim Sleimi
    Jul 8, 2020 at 12:47
  • 1
    That could have happened, yes. I know it's the case for the GoogleEarthEngine, because I had exactly the same problem (also S2 data, since the Sentinel DataHub LTA broke down a while ago) Jul 9, 2020 at 6:51
  • Yeah, I rechecked the command line and I found that I did specify the resolution at the time. Thanks a lot for your help!
    – Rim Sleimi
    Jul 9, 2020 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.