0

This question is based on a previous post: 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).

I have written the following code in geemap (based on previous question) 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?

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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