I am trying to calculate mean reflectance values across landsat 5 and 8 images using the following code:

var point = /* color: #d63000 */ee.Geometry.Point([-133.49, 69.18]);

var l5 = ee.ImageCollection('LANDSAT/LT05/C01/T1')

var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
 return image.rename(['B5']);

var stack = ee.ImageCollection(l5.merge(l8));
   var mean = stack.select(['B5'])

 Map.addLayer(mean, {});

which gives this error:

enter image description here

I have tried return image.rename(['B5']).toShort(); with similar results


I think you accidentally picked the wrong image collections:

You have now selected the 'raw-scenes' collection for landsat 5, which are indeed in 8bits stored, and the 'top-of-the-atmosphere' (TOA) collection for Landsat 8, which are indeed in floating values.

As you did not run any TOA-calibration in your script, you probably just want to select both TOA collections:

var l5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_TOA')

Then you don't need any casting. Link code. As a suggestion, I renamed the band to the standardized name (SWIR1) using .select(oldNames, newNames), which makes it easier to compare Landsat 8 with the previous collections.


With the images that you are using, if you inspect the bands, the data type of B5 for l5 is unsigned int 8 and that for l8 is float. You were on the right track with the casting .toShort() but from what i can tell it was only applied on the l8 collection as the l5 collection is not mapped. You can apply same mapping function to both collections and cast their images but i think the easiest way would be to do that after the merge.

var stack = ee.ImageCollection(l5.merge(l8));

stack = stack.map(function(image){
  return image.select(['B5']).toFloat();

I casted it to float because l8 band was in float and since i am not exporting it i would like to preserve as much information as i can for computations. You can cast it to short depending on your needs.

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.