closest#

abstract geetools.ee_image_collection.ImageCollectionAccessor.closest(date, tolerance=1, unit='month')#

Gets the closest image (or set of images if the collection intersects a region that requires multiple scenes) to the specified date.

Parameters:
  • selfee.ImageCollection from which to get the closest image to the specified date.

  • date (ee.Date | str) – Date of interest. The method will look for images closest to this date.

  • tolerance (int) – Filter the collection to [date - tolerance, date + tolerance) before searching the closest image. This speeds up the searching process for collections with a high temporal resolution.

  • unit (str) – Units for tolerance. Available units: year, month, week, day, hour, minute or second.

Returns:

Closest images to the specified date.

Return type:

ee.ImageCollection

Examples

import ee
import geetools

ee.Initialize()
geom = ee.Geometry.point(-122.196, 41.411)
s2 = (
    ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
    .filterBounds(geom)
    .geetools.closest('2020-10-15')
)
s2.size().getInfo()