Reduce ImageCollection#
THe Earth Engine API provides 2 ways to reduce images: reduceRegion and reduceRegion. geetools is making these methods also available for ee.ImageCollection objects.
Set up environment#
Install all the required libs if necessary and perform the import statements upstream.
# uncomment if installation of libs is necessary
# !pip install earthengine-api geetools
import ee
import geetools #noqa: F401
# uncomment if initialization is required
# ee.Initialize()
Example data#
The following examples rely on a ee.FeatureCollection composed of three ecoregion features that define regions by which to reduce image data. The ImageCollection data loads the modis vegetation indicies and subset the 2010 2020 decade of images.
## Import the example feature collection and drop the data property.
ecoregions = (
ee.FeatureCollection("projects/google/charts_feature_example")
.select(["label", "value", "warm"])
)
## Load MODIS vegetation indices data and subset of 4 images.
vegIndices = (
ee.ImageCollection("MODIS/061/MOD13A1")
.filter(ee.Filter.date("2010-01-01", "2010-02-28"))
.select(["NDVI", "EVI"])
)
Reduce over single region#
Using reduceRegion you can reduce an ee.ImageCollection over a single region. The function will return a ee.Dictionary with the reduced values of each band grouped under each image Id as key.
It will return a ee.Dictionary with the following shape:
{
"image1": {"band1": value1, "band2": value2, ...},
"image2": {"band1": value1, "band2": value2, ...},
}
where image*is the id of the image as per specified property (casted to string) and band* is the name of the band.
vegIndices.geetools.reduceRegion(
reducer = ee.Reducer.mean(),
idProperty = "system:time_start",
idType = ee.Date,
geometry = ecoregions.filter(ee.Filter.eq("label", "Forest")).geometry(),
scale = 500
).getInfo()
{'2010-01-01T00-00-00': {'EVI': 1912.5637702562262, 'NDVI': 3273.672377532786},
'2010-01-17T00-00-00': {'EVI': 3276.7642398350026, 'NDVI': 7331.223758333469},
'2010-02-02T00-00-00': {'EVI': 2963.2602251579947, 'NDVI': 7845.514550793475},
'2010-02-18T00-00-00': {'EVI': 3276.4948281435295, 'NDVI': 7951.898544727663}}