Wednesday, 18 July 2018

Earth Engine mismatched type for band


I'm trying to calculate the average Julian day of year for greenness decrease from the MODIS MCD12Q2 dataset. Following is the code and error, which comes from having to normalize the julian day within each year using the apply_offset() function. There are several similar questions on here with this error, but I can't figure out how to fix it here.


// The values of MCD12Q2 are "Days since Jan. 1, 2000"
// This is the offset needed to convert to the relative Julian day for the year
var all_doys = ee.List.sequence(1,366);
var apply_offset = function(image){
var day_offset = image.date().difference('2000-01-01','day');
return image.subtract(day_offset).multiply(-1);
}


var all_years = ee.ImageCollection('MODIS/MCD12Q2')
.select(['Onset_Greenness_Decrease1'])
.map(apply_offset);


print(all_years)
var mean_decrease = all_years.reduce(ee.Reducer.mean());
print(mean_decrease)

var viz_options = {

min: 0,
max: 365,
palette: ['0f17ff', 'b11406', 'f1ff23'],
};
Map.addLayer(
mean_decrease.select('Onset_Greenness_Decrease1_mean'), viz_options,
'Mean Decrease');

The error:


Mean Decrease: Tile error: Expected a homogeneous image collection,

but an image with an incompatible band was encountered.
Mismatched type for band 'Onset_Greenness_Decrease1':
Expected: Type>.
Actual: Type>.
Image ID: null
This band might require an explicit cast.

Answer



As the error says, just explicitly cast the new image band. The image showed correctly on the screen if I add casting toFloat:


var all_doys = ee.List.sequence(1,366);
var apply_offset = function(image){

var day_offset = image.date().difference('2000-01-01','day');
return image.subtract(day_offset).multiply(-1).toFloat();
};

Full code


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...