reduceRegion#

geetools.ee_image_collection.ImageCollectionAccessor.reduceRegion(reducer, geometry, idProperty='system:index', idType=ee.Number, idReducer='first', idFormat=None, scale=None, crs=None, crsTransform=None, bestEffort=False, maxPixels=None, tileScale=1)#

Apply a reducer to all the pixels in a specific region on each image of the collection.

The result will be shaped as a dictionary with the idProperty as key and for each of them the reduced band values.

{
    "image1": {"band1": value1, "band2": value2, ...},
    "image2": {"band1": value1, "band2": value2, ...},
}

Warning

The method makes a call to the pure Python uuid package, so it cannot be used in a server-side map function.

Parameters:
  • idProperty (str) – The property to use as the key of the resulting dictionary. If not specified, the key of the dictionary is the index of the image in the collection. One should use a meaningful property to avoid conflicts. in case of conflicts, the images with the same property will be mosaicked together (e.g. all raw satellite imagery with the same date) to make sure the final reducer have 1 single entry per idProperty.

  • reducer (str) – THe reducer to apply.

  • idType (type) – The type of the idProperty. Default is ee.Number. As Dates are stored as numbers in metadata, we need to know what parsing to apply to the property in advance.

  • idReducer (str | ee.Reducer) – If the multiple images have the same idProperty, they will be aggregated beforehand using the provided reducer. default to a mosaic behaviour to match most of the satellite imagery collection where the world is split for each date between multiple images.

  • idFormat (str | ee.String | None) – If a date format is used for the IdProperty, the values will be formatted as “YYYY-MM-ddThh-mm-ss”. If a number format is used for the IdProperty, the values will be formatted as a string (“%s”). You can specify any other format compatible with band names.

  • geometry (ee.Geometry) – The region over which to reduce the data.

  • scale (int | float | None) – A nominal scale in meters to work in.

  • crs (str | None) – The projection to work in. If unspecified, the projection of the image’s first band is used. If specified in addition to scale, rescaled to the specified scale.

  • crsTransform (list | None) – The list of CRS transform values. This is a row-major ordering of the 3x2 transform matrix. This option is mutually exclusive with ‘scale’, and replaces any transform already set on the projection.

  • bestEffort (bool) – If the polygon would contain too many pixels at the given scale, compute and use a larger scale which would allow the operation to succeed.

  • maxPixels (int | None) – The maximum number of pixels to reduce.

  • tileScale (float) – A scaling factor between 0.1 and 16 used to adjust aggregation tile size; setting a larger tileScale (e.g., 2 or 4) uses smaller tiles and may enable computations that run out of memory with the default.

Returns:

A dictionary with the reduced values for each image.

Return type:

ee.Dictionary

Examples

import ee
import geetools
from geetools.utils import initialize_documentation
import pandas as pd

initialize_documentation()

## Import the example feature collection and drop the data property.
ecoregion = (
    ee.FeatureCollection("projects/google/charts_feature_example")
    .select(["label", "value", "warm"])
    .first()
)

## Load MODIS vegetation indices data and subset a decade of images.
vegIndices = (
    ee.ImageCollection("MODIS/061/MOD13A1")
    .filter(ee.Filter.date("2010-01-01", "2010-05-30"))
    .select(["NDVI", "EVI"])
)

data = vegIndices.geetools.reduceRegion(
    geometry=ecoregion.geometry(),
    reducer="mean",
    idProperty="system:time_start",
    idType=ee.Date,
    scale=10000,
)

# display them as a dataframe
df = pd.DataFrame(data.getInfo()).transpose()
df.head(15)
EVI NDVI
2010-01-01T00-00-00 1029.865316 1829.181223
2010-01-17T00-00-00 981.652473 1919.515781
2010-02-02T00-00-00 984.046138 1852.502812
2010-02-18T00-00-00 1001.357741 1821.733272
2010-03-06T00-00-00 1096.367439 1814.529324
2010-03-22T00-00-00 1264.786813 1918.765178
2010-04-07T00-00-00 1397.797831 2200.882876
2010-04-23T00-00-00 1512.982670 2305.773155
2010-05-09T00-00-00 1531.141168 2265.504017
2010-05-25T00-00-00 1504.562780 2207.268966