0

I would like to use Earth Engine to sample raster data via points and save that information to a local file. I do this by creating a FeatureCollection of point geometries and then pass that structure to a reduceRegions call. I iterate over the result of getInfo to get the sampled raster data. However, the runtime of this function is much much slower than I would have expected. Is there any way to get runtime feedback about a job that is being processed on GEE, or a better way to asynchronously request jobs for a client side download?

This is a simplified, but functional, version of what I'm trying to do that takes 30ish seconds the first time I run it. My actual data includes thousands of points and the wait time makes me wonder if I've done something wrong.

import ee


def main():
    """Entry point."""
    ee.Initialize()

    pts = ee.FeatureCollection([
      ee.Feature(ee.Geometry.Point([-118.6010, 37.0777])),
      ee.Feature(ee.Geometry.Point([-118.5896, 37.0778])),
      ee.Feature(ee.Geometry.Point([-118.5842, 37.0805])),
      ee.Feature(ee.Geometry.Point([-118.5994, 37.0936])),
      ee.Feature(ee.Geometry.Point([-118.5861, 37.0567]))
    ])

    img = ee.ImageCollection("LANDSAT/LT05/C01/T1_8DAY_NDVI").filterDate('1997-01-01', '2019-01-01')
    mean_img = img.reduce(ee.Reducer.mean())
    samples = mean_img.reduceRegions(**{
        'collection': pts,
        'scale': 30,
        'reducer': 'mean'}).getInfo()  #  <<< takes a long time to run! better way to do this?
    for sample in samples['features']:
        print(f"{sample['geometry']['coordinates']}, {sample['properties']['mean']}")


if __name__ == '__main__':
    main()

Rich
  • 12,068
  • 9
  • 62
  • 94
  • I’m voting to close this question because it belongs on gis.stackexchange.com – Rich Oct 11 '21 at 18:57
  • 1
    What it taking that much time is most likely getting the mean value for the stack of images. Consider the number of images it has to access in that time! – Jesse Anderson Oct 12 '21 at 16:07

1 Answers1

0

Usually displaying the result takes ages (e.g.your print function). Try instead exporting the sampled table as a csv to your Google drive repo. This should speed up significantly your work. But it can still take quite some time!

Jo Wag
  • 1