Saturday, 1 August 2015

Getting Error: exported bands must be compatible from Google Earth Engine


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,
});

Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...