0

I'm stuck trying to combine two images due to the following error. The type for the bands are both floats, but as the error shows, are not quite the same:

Scaled LST: Tile error: Expected a homogeneous image collection, but an image with an incompatible band was encountered. Mismatched type for band 'LST_Day_1km':
Expected type: Float<0.0, 2184.5>.
  Actual type: Float<-3274.25, 2.5>.
     Image ID: 1
This band might require an explicit cast.

I've attached my script below, I've seen other threads seemingly addressing similar issues. I'm very new to Java.

//Loading in the Modis EVI data
var evi = ee.ImageCollection('MODIS/MOD09GA_006_EVI')
                  .filter(ee.Filter.date('2020-08-01', '2020-08-30'));
var colorized = evi.select('EVI');
var colorizedVis = {
  min: 0.0,
  max: 1.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(colorized, colorizedVis, 'EVI');



// Use the expression function to generate scaled EVI.

var scaledevi = evi.map(function (evi) {
  return evi.expression(
    '(evi - 0.1)',{
      'evi': evi.select('EVI')
    });
});


Map.addLayer(scaledevi, {bands: 'EVI', max: 1 , min: 0}, 'scaledevi',false);


//Loading in the Modis LST data
var lst = ee.ImageCollection('MODIS/006/MOD11A1')
                  .filter(ee.Filter.date('2020-08-01', '2020-08-30'));
var landSurfaceTemperature = lst.select('LST_Day_1km');
var landSurfaceTemperatureVis = {
  min: 13000.0,
  max: 16500.0,
  palette: [
    '040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6',
    '0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef',
    '3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f',
    'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d',
    'ff0000', 'de0101', 'c21301', 'a71001', '911003'
  ],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(landSurfaceTemperature, landSurfaceTemperatureVis, 'Land Surface Temperature');


// Use the expression function to generate scaled LST.

var scaledlst1 = lst.map(function (lst) {
  return lst.expression(
    '(lst/30)',{
      'lst': lst.select('LST_Day_1km')
    });

});

Map.addLayer(scaledlst1, {band:'LST_Day_1km' ,max: 1 , min: 0}, 'scaledlst1');

//

var scaledlst2 = lst.map(function (lst) {
  return lst.expression(
    '(lst * (-0.05)) + 2.5',{
      'lst': lst.select('LST_Day_1km')
    });

});

Map.addLayer(scaledlst2, {band:'LST_Day_1km', max: 1 , min: 0}, 'scaledlst2');


//select images

var ListOfImages1 = scaledlst1.toList(scaledlst1.size())
var ListOfImages2 = scaledlst2.toList(scaledlst2.size())


var LST = ee.Image(ListOfImages1.get(0))


var LST2 = ee.Image(ListOfImages2.get(0))




//Take min value
var scaledLST = ee.ImageCollection.fromImages([LST,LST2]).min()

Map.addLayer(scaledLST, {max: 1 , min: 0}, 'Scaled LST');
0

You can explicitly cast each image inside scaledlst1 and scaledlst2 to float. That ensures that they have the same type:

var scaledlst1 = lst.map(function (lst) {
  return lst.expression(
    '(lst/30)',{
      'lst': lst.select('LST_Day_1km')
    }).float()
})

var scaledlst2 = lst.map(function (lst) {
  return lst.expression(
    '(lst * (-0.05)) + 2.5',{
      'lst': lst.select('LST_Day_1km')
    }).float()
})

https://code.earthengine.google.com/6e150c72a802e9828910d71f185c49f5

1
  • Thank you! I was unsure how to successfully cast them to float. Much appreciated. – Labguyvancouver May 28 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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