I have an ImageCollection containing FIRMS fire image in 2014. I want to count the number of fires in the year for a predefined region. I can find a way to count the number of fires for an individual image through the use of ee.Image.reduceRegion
.
However, I cannot figure out a way to summing up individual image's fire count to derive total fire count for 2014.
Here's my code:
// Load Vietnam shapefile
var vn_shape = ee.FeatureCollection('users/chucmd/VNM_adm0');
print (vn_shape);
// Load fire counts image
var fire = ee.ImageCollection('FIRMS').filterBounds(vn_shape).filterDate('2014-01-01', '2014-03-30');
// Clip image to Vietnam
var fire_vn = fire.map(function(image) {return image.clip(vn_shape);});
print (fire_vn);
// Filter fire with more than 50% confidence and add a new band representing areas where confidence of fire > 50%
var filterConfidence = function(image) {
var line_number = image.select('line_number');
var confidence = image.select('confidence');
var conf_50 = confidence.gt(50).rename('confidence_50');
var count_band = line_number.multiply(conf_50).rename('count');
return image.addBands(count_band);
};
var fire_conf_vn = fire_vn.map(filterConfidence);
print (fire_conf_vn);
// fire count for individual image
var img1 = ee.Image(fire_conf_vn.first());
print (img1);
var countObject = img1.reduceRegion({
reducer: ee.Reducer.countDistinct(),
scale: 1000,
geometry: vn_shape
});
print (countObject);
Best Answer
Summing up attributes of images in an ImageCollection can be done using ee.ImageCollection.aggregate_sum().
A few other changes I made:
Here is the resulting script: