0

I want to map a function to count how many pixels in my study area have been detected as a hotspot at least once, by month, for a given time period. I want the output to be a list of hotspot counts for each month. I'm using MODIS Aqua and Terra data, and I've merged them together. When I run the function, I get the error: "Image.gte: If one image has no bands, the other must also have no bands. Got 0 and 1." I filtered the merged data to make sure there were no images with empty bands, but I still get this error. Does this have to do with the fact that I merged Aqua and Terra data? How can I fix it?

Code is here: https://code.earthengine.google.com/c4db2521035b3f46af7e810b3c1889e8 The relevant section is reproduced below:

var terra = ee.ImageCollection("MODIS/061/MOD14A1").select('FireMask','MaxFRP')
  .filterDate(start, end);
var aqua = ee.ImageCollection("MODIS/061/MYD14A1").select('FireMask','MaxFRP')
  .filterDate(start, end);

// Merge Terra and Aqua hotspots to include more overpass times
var hotspots_all = ee.ImageCollection(terra.merge(aqua)).sort("system:time_start");

// Clip imagery to area
var hotspots = hotspots_all.map(function(image) { return image.clip(geometry).reproject('EPSG:4326', null, 1000); });

// Find the images with missing bands, and get rid of them (these are data outages)
var filteredHotspots = hotspots.filter(ee.Filter.listContains('band_names', 'MaxFRP'));

// Display Hotspots on the map.
var fire_viz = {min: 1, max: 10, palette: ['lightsalmon','red','darkred']}; // show range for number of times the same pixel has been detected
Map.addLayer(hotspots_masked.select('MaxFRP').count().clip(geometry), fire_viz, 'Hotspots Count (masked)'); // for plain color: use {palette: 'orange'} 

print(hotspots_masked, 'MODIS Hotspots (Terra + Aqua, masked)');


///////////////////////////////////////////////////////////////////////
// Get Monthly hotspot counts (burn days): map over years and months
var years = ee.List.sequence(start_year, end_year);
var months = ee.List.sequence(start_month, end_month);

var hotfrp_mask = filteredHotspots.select('MaxFRP');  // or use hotspots_masked


var monthlyCount = years.map(function(y) {
  var yearCollection = hotfrp_mask.filter(ee.Filter.calendarRange(y, y, 'year'));   //using the masked QC'ed imagery
  var byYear = months.map(function (m){
    var totalCount = yearCollection.filter(ee.Filter.calendarRange(m, m, 'month'))  // get all images in a month time period (there are multiple observations every day)
      // Count the number of non-masked in the stack at each pixel
      .count();  // Output: One image where each pixel is the number of unmasked pixels (hotspots) in the input stack.
    
    // Sum up all the hotspot pixel counts for each month for the geometry
    var getBurnCount = totalCount.updateMask(totalCount.gte(1)) // Update mask: keep all counts at or above 1
    .reduceRegion({
        reducer: ee.Reducer.sum().unweighted(),   // Get region-wide sum of the pixel counts, unweighted. 
        geometry: geometry,
        scale: 1000,              // This is the scale of the hotspot data product
        maxPixels: 1e13
      });  
   // reduceRegion() returns a dictionary with the sum of unmasked pixels for each month for the geometry
   
    //var countValue = totalCount.get('count');
    var countValue = ee.Dictionary(getBurnCount).get('MaxFRP'); // get value associated with dict key - is this what the band will be called?
    
    var f = ee.Feature(null, {  //originally ee.Feature(null, {})
      'year': y,
      'month': m,
      'hotspot_count': countValue
    });
    return f;
  });
  return byYear.flatten();
});
// The result is the total number of times a hotspot was detected ONE OR MORE times for each month.
//     This solves the problem of double-counting hotspots detected by both Terra and Aqua. However, 
//     it reduces the total hotspot count for each month.


// Print to see output
print("monthlyCount", monthlyCount);
print("monthly Count flat", monthlyCount.flatten());

var monthlyList = monthlyCount.flatten();  // convert to list of all months (from list of lists)
1
  • your code can't be replicated. Provide the necessary information that are not defined: start, end, start_year, end_year, start_month, end_month, geometry, hotspots_masked
    – Es_a
    Commented Aug 25 at 16:33

1 Answer 1

1

This error means that there are images with no bands encountered inside map when evaluating gte(1). Most likely, one or more of the output of a filter are an empty collection that is reduced to an image without any band at somepoint. In your code filter(ee.Filter.listContains('band_names', 'MaxFRP')) returns 0 and should be omitted.

However, your code can't be replicated as you didn't provide any of the necessary information. The date range variables and necessary information are not declared : start, end, start_year, end_year, start_month, end_month, geometry, hotspots_masked

Note 1: This can also happen in if you provide inconsistent input date ranges for month and year filters, where one can return empty collection. See below and the code here for example reproducing the error and solving it based on the date range.

var start = '2018-01-01'
var end = '2020-12-31' // this date work
var end = '2020-12-01'//this date doesn't work because it returns Dec2020 empty
var start_year = 2018
var end_year = 2020
var start_month = 1
var end_month = 12

Note 2: the line here is also unnecessary

// Clip imagery to area
var hotspots = hotspots_all.map(function(image) { return image.clip(geometry).reproject('EPSG:4326', null, 1000); });
1
  • Thanks! The problem was with my start and end dates. It was returning empty months, as you showed in your example.
    – KatieGeo
    Commented Aug 26 at 9:58

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.