This question is based on a previous post: https://gis.stackexchange.com/questions/386827/filter-two-image-collections-by-the-same-aqusition-date-in-google-earth-engine
I would like to expand the question to try to filter collections to get images that are within one day of each other (i.e., image from collection 1 is within +/- one day of image from collection 2) in Google Earth Engine (python api).
I have written the following code in geemap (based on previous post) to get coincident image dates, given two image collections:
col1 = ee.ImageCollection('LANDSAT/LE07/C02/T1_L2') \
.filter(ee.Filter.calendarRange(1998, 2013,'year')) \
.filterBounds(pts)
col2 = ee.ImageCollection('LANDSAT/LT05/C02/T1_L2') \
.filter(ee.Filter.calendarRange(1998, 2012,'year')) \
.filterBounds(pts)
def datefunc(image):
date = ee.Date(image.get('system:time_start')).format("YYYY-MM-dd")
date = ee.Date(date)
return image.set('date', date)
col1_date = col1.map(datefunc)
col2_date = col2.map(datefunc)
filterTimeEq = ee.Filter.equals(
leftField='date',
rightField='date'
)
simpleJoin = ee.Join.simple()
col_new = ee.ImageCollection(simpleJoin.apply(col1_date, col2_date, filterTimeEq))
Is there any way I can modify the above code to get near coincident imagery?
Solved! I got it working using ee.Filter.maxDifference
. I used the original 'system:time_start'
values (which are in milliseconds) and set the max difference as one day. The full code looks like this:
filterNear = ee.Filter.maxDifference(
difference = 86400000,
leftField='system:time_start',
rightField='system:time_start'
)
col_near = ee.ImageCollection(simpleJoin.apply(col1, col2, filterNear))
Where 86400000 is the number of milliseconds in 24 hours.