I'm struggling to write code to get fire frequency for several sample areas from 2000-2020. I'd like to get the frequency of fire in each of my sample areas (called samplesin my code) and then separate these areas by low, medium, and high fire frequency into different FeatureCollections.

My current code just produces 3 FeatureCollections with the same number of Objects so it does not seem correct. I think the error occurs either when I try to use the band BurnDate to get the total number of days when fires occurred or when I try to subset the data by low, medium, and high fire frequency.

Here is my code:


var boundary = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017");
var SA = boundary.filter(ee.Filter.eq('country_na', 'South Africa'));
//Generate random points
var points = ee.FeatureCollection.randomPoints(
    {region: SA, points: 100, seed: 0, maxError: 1});
//print('points', points);
//create buffers around points of interest
var pointsgeo = points.geometry();
var samples = pointsgeo.buffer(10);
///Load MODIS fire dataset
var fire = ee.ImageCollection("ESA/CCI/FireCCI/5_1")
  .map(function(image){return image.clip(samples)})
  .filterDate('2000-01-01', '2020-12-31');
var firedate = fire.select('BurnDate');
var getfiredays = function(image){
  return image.gte(0);
var firedays = firedate.map(getfiredays);
//Get total number of days with fire over past 20 years
var firedays = firedays.reduce(ee.Reducer.sum());
//Get average number fire days per year
var firedays = firedays.divide(20);
///Separate into samples with low, med, and high fire frequency
var lowfire = firedays.lte(15);
var medfire = firedays.gt(15).lt(50);
var highfire = firedays.gte(50);

var low = lowfire.reduceToVectors({
  geometry: samples,
  crs: lowfire.projection(),
  scale: 10,
  eightConnected: false,

var med = medfire.reduceToVectors({
  geometry: samples,
  crs: medfire.projection(),
  scale: 10,
  eightConnected: false,

var high = highfire.reduceToVectors({
  geometry: samples,
  crs: highfire.projection(),
  scale: 10,
  eightConnected: false,

1 Answer 1


Here's a solution to obtain the desired output. The first thing you need to change is defining the low, med and high fire images using an and, so you can use two conditions. The next suggestion is that you sum these three images to obtain an image with 4 values: 0, no burn, 1, low, 2, med, 3, high; and then, instead of using reduceToVectors, you can use sampleRegions to obtain the values of the image in the samples location. Finally, you just need to separate the collection into three collections using its property 'BurnDate_sum'.

///Separate into samples with low, med, and high fire frequency
// Add 'and' to reclassify values according to two conditions
var lowfire = firedays.lte(15).and(firedays.gt(0));
var medfire = firedays.gt(15).and(firedays.lt(50));
var highfire = firedays.gte(50);
// low will have values = 1, med = 2, high = 3.
var pre = lowfire.add(medfire)
// Mask values = 0 or stay with values not equal to zero                 
pre = pre.updateMask(pre.neq(0));

print('pre', pre);
print('samples', samples);

// Sample the raster according to your raster
var resul = pre.sampleRegions({
  collection: samples,
  scale: 10,

Map.addLayer(resul, {}, 'resul');
print('resul', resul);

// Check all the values of BurnDate_sum property
// All are in the low class (i.e., BurnDate_sum = 1)

// Make the three collections
var low = resul.filter(ee.Filter.eq('BurnDate_sum', 1));
var med = resul.filter(ee.Filter.eq('BurnDate_sum', 2));
var high = resul.filter(ee.Filter.eq('BurnDate_sum', 3));

print('low', low);
print('med', med);
print('high', high);
  • This is helpful however when I switch my initial area of interest from South Africa to another country (necessary for my purposes) it results in over 100 elements when using the line print(resul.aggregate_array('BurnDate_sum'));. Additionally the printed list only contains 1s even when I adjust the thresholds fire frequency
    – Isabel
    Jan 25, 2023 at 17:14
  • 1
    When I ran the previous code I remember that most of the values in firedays had values between 0 and 1, due to the division by 20 to get the average number fire days per year. You could try to add that layer to the Map area to check the values in the image and set the thresholds accordingly. Finally, the aggregate_array part should output a list with the same number of elements as the sample collection. Jan 25, 2023 at 17:42

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.