I'm interested in transitions that occur on a date, such as bushfires. I want to get the closest (in time) cloud-free landsat image possible using as many images as necessary in the collection up until that date. It's easy to make a cloud-free collection of images using the map function but then I want the masked pixels of the image closest to the date to the filled (where possible) with the previous image and if that is also masked, the next previous etc. I thought of using imagecollection.qualityMosaic with a layer of the deltadays from the final date to control mosaicing process but I cannot manipulate the image date in the imageCollection.map function as it is external. There also may be a much simpler way to do this. I'm new to Python and GEE (but not programming) which is certainly not helping. Any ideas?
After reading carefully your question, I've realized that what you need is a function I have incorporated in
from geetools import tools masked_collection = ee.ImageCollection('a masked col') filled_collection = tools.imagecollection.fill_with_last(masked_collection)
The hardcoded version is:
def fill_with_last(collection): """ Fill masked values of each image pixel with the last available value :param collection: the collection that holds the images that will be filled :type collection: ee.ImageCollection :rtype: ee.ImageCollection """ new = collection.sort('system:time_start', True) collist = new.toList(new.size()) first = ee.Image(collist.get(0)).unmask() rest = collist.slice(1) def wrap(img, ini): ini = ee.List(ini) img = ee.Image(img) last = ee.Image(ini.get(-1)) mask = img.mask().Not() last_masked = last.updateMask(mask) last2add = last_masked.unmask() img2add = img.unmask() added = img2add.add(last2add) \ .set('system:index', ee.String(img.id())) props = img.propertyNames() condition = props.contains('system:time_start') final = ee.Image(ee.Algorithms.If(condition, added.set('system:time_start', img.date().millis()), added)) return ini.add(final.copyProperties(img)) newcol = ee.List(rest.iterate(wrap, ee.List([first]))) return ee.ImageCollection.fromImages(newcol)
Can't you just filter images by time and try to create a mosaic with these images? So, first filter:
temporalFiltered = spatialFiltered.filterDate('2016-01-01','2016-12-28')
and then do the mosaic? And if this does not work you'll just have to increase the window of dates!
I've been pulled off this by other dramas but someone posted (thanks for that) a very helpful post on 'Best Available Pixel' that definitely had useful info in it. It's taking me a while to digest.
Oh there you are in a comment above. Thanks Rodrigo E. Principe