I have not used ee.Algorithms.Landsat.simpleCloudScore
before but it appears to have been written for TOA images. .clipToCollection()
clips an ee.Image()
to an ee.FeatureCollection
(see documnetation.
A solution to the problem is to,
- Create a cloud mask using the QA band included in Landsat SR products
- Count the number of pixels in your ROI that are masked
- Add the pixel count as an image property and use it to filter your image collection
Say lan8
is an ee.ImageCollection
and ROI
is an ee.Geometry
:
var lan8_filt = lan8
.map(function(image){
// first create cloud_mask using the QA band (there is a tutorial on the GEE website somehwere, but I could not find the link
// bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = 1 << 3
var cloudsBitMask = 1 << 5
// get pixel QA band
var qa = image.select('pixel_qa');
// set clouds and cloud shadows to 0
var cloud_mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0))
.rename('cloud_mask')
// next get the fraction masked pixels in the roi
// reduce a histogram over the cloud mask
var hist = ee.Dictionary(cloud_mask.reduceRegion({reducer: ee.Reducer.frequencyHistogram(),
geometry: ROI, maxPixels:1e10}).get('cloud_mask'))
// get total pixel count
var N = hist.values().reduce(ee.Reducer.sum())
// get relative histogram
var histr = hist.map(function(key,val){return ee.Number(val).divide(N).multiply(100).int()})
// return image with cloud mask and new properties which are relative counts ('0' is masked pix and '1' is non-masked pix)
return image.addBands(cloud_mask).set(histr)
})
// filter collection for 100% cloud cover (i.e. i.e. count for '1' is null)
.filter(ee.Filter.notNull(['1']))
// filter collection for quality pixels in the ROI. say less than 10% cloud cover
.filter(ee.Filter.gt('1',90))