ee.data.computePixels (Python only)
Computes a tile by performing an arbitrary computation on image data.
Returns:
The pixels as raw image data.
Usage | Returns |
ee.data.computePixels(params) | Object|Value |
Argument | Type | Details |
params | Object | An 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
# 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...
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["`ee.data.computePixels` computes a tile by performing an arbitrary computation on image data and returns the pixels as raw image data."],["The `params` argument to `ee.data.computePixels` allows for customizing the computation through an expression, file format, pixel grid, band selection, visualization options, and workload tag."],["The provided Python example demonstrates using `ee.data.computePixels` to retrieve a PNG image tile from a Sentinel-2 median composite with specified visualization and grid parameters."]]],[]]