1
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.

2
  • I'm unable to replicate this. You haven't specified roi, perhaps it's only showing up for some specific area. Update your question and include it. Feb 18, 2022 at 11:31
  • I've just updated. Thank you!
    – Shevk1
    Feb 19, 2022 at 9:17

3 Answers 3

0

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');
0

We are updating all images in this collection to have MSK bands (which might be empty). This is almost done, but meanwhile such errors might indeed occur.

-1
var dataset = ee.FeatureCollection("users/mpangihutan/Jawa Tengah");

function maskS2clouds(image) {
  var qa = image.select('ST_ATRAN');

  // Bits 10 and 11 are clouds and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;

  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
      .and(qa.bitwiseAnd(cirrusBitMask).eq(0));

  return image.updateMask(mask).divide(10000);
}

// Load Landsat LC08 reflectance data.
var lc8 = ee.FeatureCollection('LANDSAT/LC08/C01/T1_SR')
                  .filterDate('2013-01-01', '2013-12-31')
                  .filter(ee.Filter.lt('CLOUD_COVER',30))
                  .map(maskS2clouds)
                  .filter(ee.Filter.bounds(roi));

var visualization = {
  bands: ['SR_B4', 'SR_B3', 'SR_B2'],
  min: 0.0,
  max: 0.3,
};

// Proses Landsat LC08
var image = dataset.median(); 
var clipped = image.clip(roi)

var ndwi = clipped.normalizedDifference(['B3', 'B11']).rename(['ndwi']);

var tss = clipped.expression(
       "(ndwi > 0.1) ? 8.1429 * pow(VNIR,23.704* 0.94* Bandred))"+
       ": 0",{
         'ndwi' : ndwi,
         'VNIR': image.select('B7')
}).rename('tss');

var palete = ['blue','yellow','red','brown']

//print(maxTSS)

var vizTSS = {
  min: 1,
  max: 120,
  palette: palete
}

function createColorBar(titleText, palette, min, max) {
  // Legend Title
  var title = ui.Label({
    value: titleText, 
    style: {fontWeight: 'bold', textAlign: 'center', stretch: 'horizontal'}});

  // Colorbar
  var legend = ui.Thumbnail({
    image: ee.Image.pixelLonLat().select(0),
    params: {
      bbox: [0, 0, 1, 0.1],
      dimensions: '200x20',
      format: 'png', 
      min: 0, max: 1,
      palette: palette},
    style: {stretch: 'horizontal', margin: '8px 8px', maxHeight: '40px'},
  });
  
  // Legend Labels
  var labels = ui.Panel({
    widgets: [
      ui.Label(min, {margin: '4px 10px',textAlign: 'left', stretch: 'horizontal'}),
      ui.Label((min+max)/2, {margin: '4px 20px', textAlign: 'center', stretch: 'horizontal'}),
      ui.Label(max, {margin: '4px 10px',textAlign: 'right', stretch: 'horizontal'})],
    layout: ui.Panel.Layout.flow('horizontal')});
  
  // Create a panel with all 3 widgets
  var legendPanel = ui.Panel({
    widgets: [title, legend, labels],
    style: {position: 'bottom-left', padding: '8px 15px'}
  })
  return legendPanel
}
// Call the function to create a colorbar legend  
var colorBar = createColorBar('Total Suspended Soil / TSS - mg/liter', palete, 0, 120)

// Tayang peta2
//Map.addLayer(ndti, {}, 'NDTI');
//Map.addLayer(ndwi, {}, 'NDWI');
Map.add(colorBar)

    Export.image.toDrive({
  image: TSS_Masked,
  description: "tss",
  scale: 30,
  region: roi
})
1
  • 1
    A naked block of code does not make a useful Answer. Much like the Question must explain the problem, the Answer should also use text to frame the solution.
    – Vince
    Oct 4, 2023 at 15:00

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.