Google Earth Engine – Filter Sentinel-3 Data Based on Cloud Cover Over ROI

cloud-gisfilterflaggoogle-earth-enginesentinel-3

I am using a modified code (see below) from here (Filter Sentinel-2 images base on cloud cover over a region of interest) to filter Sentinel-3 images based on their cloud cover over my region of interest, but I am getting a "computing timeout" error. Anyone can help me with this? I think the main equation is how to change the reference code to work with Sentinel-3 data instead of Sentinel-2.

my code:

var ic = ee.ImageCollection("COPERNICUS/S3/OLCI");

// A polygon representing the roi.
 var geometry = ee.Geometry.Polygon(
        [[[-121.85897778617999, 37.70881514186375],
          [-121.83975284337708, 37.76202899390253],
          [-121.94137041100134, 37.759857750255144]]]);

var c = ic.filterBounds(geometry);

var getQABits = function(image, start, end, newName) {
    // Compute the bits we need to extract.
    var pattern = 0;
    for (var i = start; i <= end; i++) {
       pattern += Math.pow(2, i);
    }
    // Return a single band image of the extracted QA bits, giving the band
    // a new name.
    return image.select([0], [newName])
                  .bitwiseAnd(pattern)
                  .rightShift(start);
};

// A function to mask out cloudy pixels.
var clouds = function(image) {
  // Select the QA band.
  var QA = image.select(['quality_flags']);
  // Get the internal_cloud_algorithm_flag bit.
  return getQABits(QA, 10,10, 'cloud');
  // Return an image masking out cloudy areas.
};

var withCloudiness = c.map(function(image) {
  var cloud = clouds(image);
  var cloudiness = cloud.reduceRegion({
    reducer: 'mean', 
    geometry: geometry, 
    scale: 10,
    crs:'EPSG:32719'
  });
  return image.set(cloudiness);
});

var filteredCollection = withCloudiness.filter(ee.Filter.lt('cloud', 0.1));
print(filteredCollection);                

//my image with less clouds over my zone of interest                   
var my_image = ee.Image(filteredCollection.filterBounds(centroid)
    .filterDate('2019-01-01', '2019-01-01')
    .sort('CLOUDY_PIXEL_PERCENTAGE')
    .first());

Best Answer

As far as I can see COPERNICUS/S3/OLCI imagery doesn't contain any cloud related property you can use.

print(
  ee.ImageCollection("COPERNICUS/S3/OLCI")
    .first()
    .propertyNames()
    .join(', ')
)

Output:

SNAP_Graph_Processing_Framework_GPF_vers, processing_time, SNAP_Raster_Operators_vers, freshInlandWaterPixels, system:id, relative_orbit_num, salineWaterPixels, system:time_start, timeliness, brightPixels, system:footprint, cycle_num, system:version, system:asset_size, coastalPixels, tidalRegionPixels, status, system:index, system:bands, system:band_names

To prevent these timeout errors, you should filter your collection before mapping over it.

var ic = ee.ImageCollection("COPERNICUS/S3/OLCI")
  .filterBounds(centroid)
  .filterDate('2019-01-01', '2020-01-01')