GEE Sentinel 2 Image error: expected a homogeneous image collection, but an image with an incompatible band was encountered

google-earth-enginesentinel-2

var roi = ee.FeatureCollection("users/sevki/izmir"),
var img2017= ee.ImageCollection("COPERNICUS/S2_SR")
      .filterDate('2017-1-1', '2018-1-1')
      .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 5)
      .filterBounds(roi)
      .median()
      .select('B2', 'B3', 'B4', 'B8', 'B11', 'B12')
      .clip(roi)
      .divide(10000);
    print(img2017, 'Image 2017');

it worked yesterday but today I got the error message:

Expected a homogeneous image collection, but an image with
incompatible bands was encountered:

First image type: 23 bands ([B1, B2, B3, B4, B5, B6, B7, B8, B8A, B9, B11, B12, AOT, WVP, SCL, TCI_R, TCI_G, TCI_B, MSK_CLDPRB, MSK_SNWPRB, QA10, QA20, QA60]).

Current image type: 21 bands ([B1, B2, B3, B4, B5, B6, B7, B8, B8A, B9, B11, B12, AOT, WVP, SCL, TCI_R, TCI_G, TCI_B, QA10, QA20, QA60]).

Image ID: 20170403T090021_20170403T090840_T35SNC

Some bands might require explicit casts.

Best Answer

Checking the metadata for the two incompatible bands (MSK_CLDPRB, MSK_SNWPRB), these two might be missing in some images. I am sure there would be better solutions but a quick one might be to avoid these bands by just using the select argument first enter image description here

var img2017= ee.ImageCollection("COPERNICUS/S2_SR")
      .select('B2', 'B3', 'B4', 'B8', 'B11', 'B12')
      .filterDate('2017-1-1', '2018-1-1')
      .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 5)
      .filterBounds(roi)
      .median()
      .clip(roi)
      .divide(10000);
    print(img2017, 'Image 2017');
Related Question