-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update data conversion functions to use ee.data
methods.
#1824
Comments
Thanks, Qiusheng. I'm happy to edit too, or look, answer questions, test, review when ready- let me know! A bug was found with ee.data.computeFeatures - it currently won't return more than 1001 features. The PR should probably not be merged until the bug is fixed. |
Sure. I will wait for the fix. |
@jdbcode It seems https://developers.google.com/earth-engine/apidocs/ee-data-computepixels # 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': 'NUMPY_NDARRAY',
'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_arr = ee.data.computePixels(request)
print(image_arr.shape)
# (640, 640) instead of (640, 640, 3) |
It returns a NumPy Structured array, which is a little different than the maybe-expected-3D array. The structured array has the 3rd dimension included as tuples at the intersection of each row and column. They are accessible by name e.g.
|
Also, the example for knoxville = ee.Geometry.BBox(-84.07, 35.87, -83.79, 36.06) # some ROI
image1 = (ee.ImageCollection('COPERNICUS/S2')
.filterBounds(knoxville)
.filterDate('2020-07-01', '2020-09-01')
.median()
.setDefaultProjection('EPSG:4326', None, 20) # Or some other CRS/scale
.clipToBoundsAndScale(geometry=knoxville, scale=20)) # Clip to ROI and scale
image_arr1 = ee.data.computePixels({
'expression': image1,
'fileFormat': 'NUMPY_NDARRAY',
'bandIds': ['B4', 'B3', 'B2'],
'visualizationOptions': {'ranges': [{'min': 0, 'max': 3000}]} # Don't need to RGB
})
display(image_arr1)
import matplotlib.pyplot as plt
plt.imshow(np.dstack(([image_arr1[band] for band in image_arr1.dtype.names]))) Here is a notebook that describes the differences: https://developers.google.com/earth-engine/tutorials/community/data-converters |
Thank you for clarifying. It makes sense. |
Use
ee.data.
computeFeatures
andcomputePixels
in data conversion functions. By specifying a compatiblefileFormat
, these methods can return data in Python-native formats like structured NumPy arrays for rasters and Pandas DataFrames or GeoPandas GeoDataFrames for vectors. In the case of vectors,computeFeatures
methods will make several network requests to fetch all the pages of the table before returning the Python object.Here is a demo
ee_to_df
could benefit - what others?The text was updated successfully, but these errors were encountered: