2

I'm trying to export a tiff map and gave the following error:

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

How can I solve this?

Code:

//Choose country using GEE Feature Collection

var region = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw').filterMetadata('Country', 'equals', 'Portugal');

//Add region outline to layer ‐ for selected countries

Map.addLayer(region,{}, 'Portugal');

// image collection pre 11/10/2017

var lt8_pre = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
  .filterBounds(region) 
  .filterDate(ee.Date("2017-08-01"),ee.Date("2017-10-11")); 


Map.addLayer(lt8_pre, {bands: ['B4', 'B3', 'B2'],min: 1000, max: 1500}, 'image L8 pre');

var lt8_ndvi_pre = lt8_pre
  .map(function(img){  
  return img.addBands(img.normalizedDifference(['B5', 'B4'])).updateMask(img.select(['pixel_qa']).neq(5).neq(3).neq(2));
  });

// Create an NBR image using bands the nir and red bands (6 and 4)
var lt8_nbr_pre = lt8_pre
  .map(function(img){  
  return img.addBands(img.normalizedDifference(['B7', 'B4'])).updateMask(img.select(['pixel_qa']).neq(5).neq(3).neq(2));
  });

print(lt8_ndvi_pre);
print(lt8_nbr_pre);

// image collection pos 11/10/2017

var lt8_pos = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
  .filterBounds(region) 
  .filterDate(ee.Date("2017-10-18"),ee.Date("2018-02-10")); 

Map.addLayer(lt8_pos, {bands: ['B4', 'B3', 'B2'], max: 1000}, 'image L8 pos');

var lt8_ndvi_pos = lt8_pos
  .map(function(img){  
  return img.addBands(img.normalizedDifference(['B5', 'B4'])).updateMask(img.select(['pixel_qa']).neq(5).neq(3).neq(2));
  });

// Create an NBR image using bands the nir and red bands (6 and 4)  
var lt8_nbr_pos = lt8_pos
  .map(function(img){  
  return img.addBands(img.normalizedDifference(['B7', 'B4'])).updateMask(img.select(['pixel_qa']).neq(5).neq(3).neq(2));
  });


print(lt8_ndvi_pos);
print(lt8_nbr_pos);

//Clip to Specified Region
var NDVI_pre = lt8_ndvi_pre.mean().clip(region);
var NDVI_pos = lt8_ndvi_pos.mean().clip(region);
var NBR_pre = lt8_nbr_pre.mean().clip(region);
var NBR_pos = lt8_nbr_pos.mean().clip(region);

Map.centerObject(region, 10);
var ndvi_viz = {min:-0.8, max:1, palette:'000000,00FF00'};
Map.addLayer(NDVI_pre.select('nd'), ndvi_viz, "LT8 NDVI mean pre 11/10");
Map.addLayer(NDVI_pos.select('nd'), ndvi_viz, "LT8 NDVI mean pos 11/10");

// Display the NBRpost
var nbr_viz = {min: -1, max:1, palette: ['FFFFFF','CC9966','CC9900','996600', '33CC00', '009900','006600','000000']};
Map.addLayer(NBR_pre.select('nd'), nbr_viz, "LT8 NBR mean pre 11/10");
Map.addLayer(NBR_pos.select('nd'), nbr_viz, "LT8 NBR mean pos 11/10");

//Calcule dNBR and dNDVI
var dNBR = NBR_pre.subtract(NBR_pos);
var dNDVI = NDVI_pre.subtract(NDVI_pos);


//Map.addLayer(dNBR,nbr_viz, "dNBR");
Map.addLayer(dNDVI.select('nd'), ndvi_viz, "LT8 dNDVI");
Map.addLayer(dNBR.select('nd'), nbr_viz, "LT8 dNBR");

Export.image.toDrive({
      image: NBR_pos,
      description: 'NBR_pos',
      scale: 30,
      region: Pt,
      maxPixels: 278466375,
    });
5
  • Your code isn't reproducible. You haven't defined Pt, NBR_pos and region
    – aldo_tapia
    Commented Feb 13, 2018 at 15:45
  • I didn't wanted to paste all the code because it's little big, but It's there now. The Pt is a geometry polygon that I've made around the country. That's why didn't show up. Commented Feb 13, 2018 at 15:49
  • Please provide links to the earlier Q&As that you refer to.
    – PolyGeo
    Commented Dec 27, 2019 at 21:33
  • Also see: gis.stackexchange.com/q/345769/68792 Commented Dec 27, 2019 at 23:04
  • Regarding "export the algorithm training points": please remove from this question and ask it in a new question. Commented Dec 27, 2019 at 23:20

3 Answers 3

3

Check print(NBR_pos):

{
  "type": "Image",
  "bands": [
    {
      "id": "B1",
      "data_type": {
        "type": "PixelType",
        "precision": "double",
        "min": -32768,
        "max": 32767
      },
      "crs": "EPSG:4326",
      "crs_transform": [
        1,
        0,
        0,
        0,
        1,
        0
      ]
    },

...

    {
      "id": "sr_aerosol",
      "data_type": {
        "type": "PixelType",
        "precision": "double",
        "min": 0,
        "max": 255
      },
      "crs": "EPSG:4326",
      "crs_transform": [
        1,
        0,
        0,
        0,
        1,
        0
      ]
    },

...

    {
      "id": "pixel_qa",
      "data_type": {
        "type": "PixelType",
        "precision": "double",
        "min": 0,
        "max": 65535
      },
      "crs": "EPSG:4326",
      "crs_transform": [
        1,
        0,
        0,
        0,
        1,
        0
      ]
    },

...

    {
      "id": "nd",
      "data_type": {
        "type": "PixelType",
        "precision": "float",
        "min": -1,
        "max": 1
      },
      "crs": "EPSG:4326",
      "crs_transform": [
        1,
        0,
        0,
        0,
        1,
        0
      ]
    }
  ]
}

You have at least 4 different kinds of data type, so you can't stack bands to save as a unique raster. You can convert data type or to select bands with the same data kind to solve this issue (taking the second choice):

var NBR_pos2 = NBR_pos.select(['B1','B2','B3','B4','B5','B6','B7','B10','B11']);

Export.image.toDrive({
      image: NBR_pos2,
      description: 'NBR_pos',
      scale: 30,
      region: pt,
      maxPixels: 1e10,
    });

This should work

0
2

The error is pretty much self explanatory. The export failed because the datatype of your bands are not consistent. VV and VH bands are of type float while the angle band is of type double. You can fix this by casting your image to a certain datatype. You can set all bands to float or double or int. Granted, you might loose some level of information if you choose to cast it to something with lower data range like int.

for (var i = 0; i < count ; i++) {
  var img = ee.Image(s1.toList(1, i).get(0)).float(); // casted the image to float here
  var geom = img.geometry().getInfo();
  Export.image(img, img.get('system:index').getInfo(), {
    'scale': 20,
    'crs': 'EPSG:4326',
    'region': geometry.toGeoJSONString()
});

Other minor improvement that i suggest you to make but aren't necessary to make your code run are to use Export.image.toDrive as Export.image is deprecated and make the one list of images and then access them using get inside loop instead of creating new lists of 1 image in each loop. For example,

var s1List = s1.toList(count);
for (var i = 0; i < count ; i++) {
  var img = ee.Image(s1List.get(i)).float();
2
  1. Try casting CompImagen to float:
CompImagen = CompImagen.toFloat();

...if that does not work...

  1. Try casting each individual image composing CompImagen to float:
var imagen = dataset.median().toFloat();
var maxNDVI = dataset.select("NDVI").max().rename('ndvimax').toFloat();
// ...etc...

Additionally, you can shorten the band adding step by using ee.Image.cat():

var CompImagen = ee.Image.cat([imagen, maxNDVI, minNDVI, meanNDVI, etc]);

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.