pythonpython-3.xgoogle-earth-enginegeemap

Export imageCollection as a numpy array (Earth Engine Python API)


I'm attempting to download earth engine image collection within a specific timeframe as a 3dim numpy.ndarray with dimensions --(xdim, ydim, number of images in collection) so that I can run them on a CNN. I've been able to export one image with help of geemap tutorials and I've been able to export collections in raster format but I'm not sure how to download the collection as an array with the specified dimensions. The singular image-export in gee map exports with 3 dims as well, except the third dim turns out to be the number of bands, instead of the time series or the number of images in collection. Need some help here.

import ee
import geemap
import numpy

leaf = geemap.Map()
#leaf

startDate = ee.Date.fromYMD(2021, 1, 1);
endDate = ee.Date.fromYMD(2022, 1, 1);

dast = ee.ImageCollection("ECMWF/ERA5_LAND/DAILY_RAW").select('dew point_temperature_2m').filterDate(startDate, endDate)

geemap.ee_export_image_to_drive(
    darts, description='dew', folder='dew', region=chora, scale=500
)


Solution

  • There are multiple options. To have dimensions (xdim, ydim, number of images), the images in the collection must be one band each. Given that's the case, the first step is to call toBands() on the collection to get an image. One option is to call image with a neighborhoodToArray() on the image, then sample it at locations of interest. Example. You could also sample many patches using getDownloadUrl. Example 1, Example 2.