[GIS] Exported bands must have compatible data types; found inconsistent types: UInt16 and UInt32

google-earth-enginegoogle-earth-engine-javascript-apilandsat 8sentinel-2

What are the possible reasons for this error?

Exported bands must have compatible data types; found inconsistent
types: UInt16 and UInt32

This is the code:

Map.addLayer(PuntoQuellaveco1);
Map.addLayer(operaciones);
Map.addLayer(Abast);


 var image = ee.ImageCollection('COPERNICUS/S2')
 .filterBounds(PuntoQuellaveco1)
 .filterDate('2016-07-01','2016-08-31')
 .sort('CLOUD_COVER', false);

var conteo = image.size();
print('conteo de imágenes', conteo);

var mejorImagen = ee.Image(image.sort('CLOUD_COVER').first());

print('La primera con menos nubosidad', mejorImagen);

Map.addLayer(mejorImagen, {bands: ['B4', 'B3', 'B2'], max: 3000}, 'image');

var fechaAdquirida = mejorImagen.get('DATE_ACQUIRED');

print('Fecha adquirida', fechaAdquirida);


 Export.image.toDrive({
  image: mejorImagen,
  description: 'imageToDriveExample',
  scale: 10,
  region: Abast
   });

The variables are already created, They just can't be copied because of this:

enter image description here

Best Answer

If you have a look at Sentinel 2 bands you'll find that all bands are type unsigned int 16 except for QA20 that is unsigned int 32, that band is causing the issue.

S2 bands

You can solve it in different ways, but I post here what I think is what you need:

var image = ee.ImageCollection('COPERNICUS/S2')
              .filterBounds(PuntoQuellaveco1)
              .filterDate('2016-07-01','2016-08-31')
              .sort('CLOUD_COVER', false);

var conteo = image.size();
print('conteo de imágenes', conteo);

var mejorImagen = ee.Image(image.sort('CLOUD_COVER').first());

print('La primera con menos nubosidad', mejorImagen);

Map.addLayer(mejorImagen, {bands: ['B4', 'B3', 'B2'], max: 3000}, 'image');

var fechaAdquirida = mejorImagen.get('DATE_ACQUIRED');

print('Fecha adquirida', fechaAdquirida);

// Keep only 'B' bands
// Me quedo solo con las bandas 'B'
mejorImagen = mejorImagen.select('B.+')

Export.image.toDrive({
  image: mejorImagen,
  description: 'imageToDriveExample',
  scale: 10,
  region: Abast
   });

Or you could make QA20 and unsigned int 16 to match the others:

// Cast band's types to uint16
// Transformo los tipos de dato de las bandas a uint16
mejorImagen = mejorImagen.toUint16()
Related Question