I'm trying to execute this code but no output or error seems to be appearing. I'm not even sure what I'm doing wrong.

var collection= ee.ImageCollection('COPERNICUS/S1_GRD')
  .filter(ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'))
  // Select images by predefined dates
var reference_collection = collection.filterDate('2019-12-01', '2020-02-29');
var reference = reference_collection.mosaic().clip(aoi);

var july21 = ee.Filter.date('2020-07-20', '2020-07-22');
var july27 = ee.Filter.date('2020-07-26', '2020-07-28');
var august8 = ee.Filter.date('2020-08-07', '2020-08-09');
var august20 = ee.Filter.date('2020-08-19', '2020-08-21');

var allfloodedfilter = ee.Filter.or(july21,july27,august8,august20); // Create joint Filter

var flooded_collection = collection.filter(allfloodedfilter); //apply Filter to ImageCollection

// Apply reduce the radar speckle by smoothing 
var smoothing_radius = 50;
var applysmoother = function(anImage) {
  var smoothing_radius = 50;
  var smoother = anImage.focal_mean(smoothing_radius, 'circle', 'meters');
  return anImage.mask(smoother);
var flooded_smooth = ee.ImageCollection(flooded_collection).map(applysmoother);

var ref_smooth= function(reference) {
  var smoothing_radius = 50;
  var smoother = anImage.focal_mean(smoothing_radius, 'circle', 'meters');
  return anImage.mask(smoother);

///////////////flood extent mask
var flood_extent_mask = function(anImage) {
  var threshold = 1.25;
  var difference_binary = anImage.gt(threshold);
  return anImage.mask(difference_binary);

var masked_flood_extent = ee.ImageCollection(flooded_smooth).map(flood_extent_mask);

// Refine flood result using additional datasets
      // Include JRC layer on surface water seasonality to mask flood pixels from areas
      // of "permanent" water (where there is water > 10 months of the year)
      var swater = ee.Image('JRC/GSW1_0/GlobalSurfaceWater').select('seasonality');
      var swater_mask = swater.gte(10).updateMask(swater.gte(10));
      //Flooded layer where perennial water bodies (water > 10 mo/yr) is assigned a 0 value
      var flooded_mask = function(anImage) {
        var smask = anImage.where(swater_mask,0);
        return anImage.mask(smask);
      var smaskallocated = ee.ImageCollection(masked_flood_extent).map(flooded_mask);

//update mask
var updatesmask = function(anImage) {
        var smask = anImage.updateMask(anImage);
        return anImage.mask(smask);
var wo_smask = ee.ImageCollection(smaskallocated).map(updatesmask);

var freq = wo_smask.sum().divide(wo_smask.count());


var VisParamWar = {"bands":["VH"],"min":0,"max":1};
Map.addLayer(freq,VisParamWar,'Water freq')

2 Answers 2


The problem is that the final result does not contain information. I tracked down the issue and I think that the problem is in the applysmoother function. In this function you are using the smoother object as a mask to the input image. Thus, this process masks all the pixels in the image (Remember that masks will contain values of 0 and 1 indicating which areas should be masked or not, respectively). I think you might want to return the image smoother instead of using it as a mask over the original image. Try using this version of the applysmoother function.

var applysmoother = function(anImage) {
  var smoothing_radius = 50;
  var smoother = anImage.focal_mean(smoothing_radius, 'circle', 'meters');
  return smoother;

Although you have given your code, but still the area of interest (aoi) is missing. I think after masking consecutively, very few valid pixels (unmasked pixels) remaining in your study area. If you plot frequency of the values, you can check what values are there before and after masking.

For masking out pixels in Earth Engine you can read this Earth Engine doc Compositing, Masking, and Mosaicking.

// print a histogram to see the image value ranges
 print('Values in the first image',ui.Chart.image.histogram(flooded_collection.first(), aoi, 100))
 print('After focal smoothing',ui.Chart.image.histogram(flooded_smooth.first(), aoi, 100))
 print('After maskeing by values greater than 1.25',ui.Chart.image.histogram(masked_flood_extent.first(), aoi, 100))
 print(ui.Chart.image.histogram(freq, aoi, 100))


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.