In the below code I want to get mean precipitation value but returns error. I don't know why this happened?
code link: https://code.earthengine.google.com/e8deb9034f8384dca2cd0f132445e199
Map.centerObject(table);
Map.addLayer(table);
var starting = '2018-05-01';
var ending = '2018-10-01';
var year = '2018';
var temporalCollection = function(collection, start, count, interval, units){
var sequence = ee.List.sequence(0, ee.Number(count).subtract(1));
var originDate = ee.Date(start);
return ee.ImageCollection(sequence.map(function(i){
var startDate = originDate.advance(ee.Number(interval).multiply(i), units);
var endDate = originDate.advance(ee.Number(interval).multiply(ee.Number(i).add(1)), units);
return collection
.filterDate(startDate, endDate).mean().clip(table)
.set('system:time_start',startDate.millis())
.set('system:time_end', endDate.millis());
}));
};
var pre = function(img){
var bands = img.select('precipitationCal').clip(table).multiply(24.0);
return bands
.copyProperties(img,['system:time_start','system:time_end']);
};
var GPM = ee.ImageCollection("NASA/GPM_L3/IMERG_V06")
.filterDate(starting, ending)
.filterBounds(table)
.map(pre);
var GPMdaily = temporalCollection(GPM, starting, 153, 1, 'days')
.map(function(img){
var bandsStdv = img.reduceRegion({
reducer: ee.Reducer.stdDev(),
geometry: table,
scale: 10000
}).getNumber('precipitationCal');
var bandsMean = img.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: table,
scale: 10000
}).getNumber('precipitationCal');
var id = ee.Date(img.get('system:time_start')).format('yyyy-MM-dd');
return img.rename(id)
.set('bandsMean', bandsMean)
.set('bandsStdv', bandsStdv)
.copyProperties(img,['system:time_start','system:time_end'])
});
print(GPMdaily);
// this part returns error
var class0 =GPMdaily
.filter(ee.Filter.metadata('bandsMean','less_than', 1.1));
var class0Per = GPMdaily
.filter(ee.Filter.calendarRange(6,8,'month'))
.filter(ee.Filter.gt('bandsMean', 1.1))
.mean();
var class1PerMean = class0Per.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: table,
scale: 10000,
bestEffort: true
});
print('class0PerMean',class1PerMean);
Best Answer
Lots of operations on ImageCollections expect/need all of the images to have the same number of bands with the same names and types. In your code, you're renaming the output bands (in the second .map()) to reflect the time of the first image in each mean, giving them different names, and the
mean()
on line 73 doesn't know what to do with that.Just skip the renaming; you're just taking a mean and not doing anything with the names.