ee.data.computePixels (Python only)

Computes a tile by performing an arbitrary computation on image data.

Returns: The pixels as raw image data.

UsageReturns
ee.data.computePixels(params)Object|Value
ArgumentTypeDetails
paramsObjectAn object containing parameters with the following possible values:
expression - The expression to compute.
fileFormat - The resulting file format. Defaults to png. See ImageFileFormat for the available formats. There are additional formats that convert the downloaded object to a Python data object. These include: NUMPY_NDARRAY, which converts to a structured NumPy array.
grid - Parameters describing the pixel grid in which to fetch data. Defaults to the native pixel grid of the data.
bandIds - If present, specifies a specific set of bands from which to get pixels.
visualizationOptions - If present, a set of visualization options to apply to produce an 8-bit RGB visualization of the data, rather than returning the raw data.
workloadTag - User supplied tag to track this computation.

Examples

Python setup

See the Python Environment page for information on the Python API and using geemap for interactive development.

import ee
import geemap.core as geemap

Colab (Python)

# Region of interest.
coords = [
    -121.58626826832939,
    38.059141484827485,
]
region = ee.Geometry.Point(coords)

# Sentinel-2 median composite.
image = (ee.ImageCollection('COPERNICUS/S2')
              .filterBounds(region)
              .filterDate('2020-04-01', '2020-09-01')
              .median())

# Make a projection to discover the scale in degrees.
proj = ee.Projection('EPSG:4326').atScale(10).getInfo()

# Get scales out of the transform.
scale_x = proj['transform'][0]
scale_y = -proj['transform'][4]

# Make a request object.
request = {
    'expression': image,
    'fileFormat': 'PNG',
    'bandIds': ['B4', 'B3', 'B2'],
    'grid': {
        'dimensions': {
            'width': 640,
            'height': 640
        },
        'affineTransform': {
            'scaleX': scale_x,
            'shearX': 0,
            'translateX': coords[0],
            'shearY': 0,
            'scaleY': scale_y,
            'translateY': coords[1]
        },
        'crsCode': proj['crs'],
    },
    'visualizationOptions': {'ranges': [{'min': 0, 'max': 3000}]},
}

image_png = ee.data.computePixels(request)
# Do something with the image...