I am working with Sentinel-2 data in GEE and I added NDVI and a specific SAVI as new bands to an Image. I had an error downloading 6 bands (RGBI, and VIs) because the data type is not the same:

Error: Exported bands must have compatible data types; found inconsistent types: UInt16 and Float32.

Then I selected only the VIs (because I have already downloaded the other bands) and the error is still there but with a new data type:

Error: Exported bands must have compatible data types; found inconsistent types: Float32 and Float64.

I used the normal difference function for NDVI and a edited operation for SAVI. After that I used a operator for NDVI as well (to have 'same' result type) but the error is the same.

Do you know how to manage it to obtain the same data format to export?

Code sample:

// Parameters for Vegetation Index (NDVI-SAVI).
var nir = scene.select('B8');
var red = scene.select('B4');
var L = 0.38
var L1 = 1.38 
var ndviParams = {min: -1, max: 1, palette: ['red', 'yellow', 'green']};

//Calculating VIs
var ndvi = scene.normalizedDifference(['B8', 'B4']).rename('NDVI');
var savi = nir.subtract(red).divide(nir.add(red).add(L)).multiply(L1).rename('SAVI');

//Selecting to download
var download = ee.Image(sorted.first()).addBands(savi).addBands(ndvi).select(['B4', 'B3', 'B2','B8','NDVI','SAVI']);

Exporting requires all bands to be of the same type, if you use the function bandTypes(), you will notice indeed differences:

  • B2: signed int16
  • B3: signed int16
  • ...
  • NDVI: float ∈ [-1, 1]

So to have all bands in the same type, you would usally cast the image into the least restrictive type, which is in this case float (indeed, casting integer to float does not loose data, while float to integer would). use the function toFloat() in this case.

Reproducible example

Your code was unfortunately not reproducible, see here a simple and dummy code, showing the issue with Landsat data:

var geometry = /* color: #0b4a8b */ee.Geometry.Polygon(
        [[[-104.1558837890625, 42.950391774502876],
          [-104.13665771484375, 42.83569550641452],
          [-103.831787109375, 42.85784648372956],
          [-103.84002685546875, 42.95441233121331]]]);

var imageCollection = ee.ImageCollection("LANDSAT/LE07/C01/T2_SR");
var image_one = ee.Image(imageCollection.first())

//Calculating VIs
var ndvi = image_one.normalizedDifference(['B3', 'B4']).rename('NDVI');
var image_one_withNDVI = image_one.addBands(ndvi)
print(image_one_withNDVI, "image_one_withNDVI")

First try: export without toFloat():

  image: image_one_withNDVI,
  description: "test_task", 
  fileNamePrefix: "test", 
  region: geometry, 

This will return: Error: Exported bands must have compatible data types; found inconsistent types: Int16 and Byte.

Second try, use: ge_one_withNDVI.toFloat()

  image: image_one_withNDVI.toFloat(),
  description: "test_task_OK", 
  fileNamePrefix: "test_OK", 
  region: geometry, 
  • Yes Matifou, the issue was with the float data type. Just transforming the adapted SAVI layer to float with .float() solves the problem. – Josep Pinyol Jul 23 '18 at 11:40

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.