2

I print a chart in the Earth Engine code editor using ui.Chart.series. I would like to extract the values of this chart using the Earth Engine API in Python to produce my own chart with matplotlib.

here l8 is any ee.imageCollection having 'cloud and 'NDMI' band and point is a ee.Geometry.Point.


var buffer = point.buffer(30);
print(ui.Chart.image.series(l8.select(['cloud', 'NDMI']), buffer, ee.Reducer.mean(), 30));

Is there a function to extract the data as a ee.list or a ee.dictionary or can I found somewhere what is under the hood of this function ?

1 Answer 1

2

What I would do is map a function over l8 that reduces the bands over buffer and then adds the reduced values as an image property (i.e. metadata). I would then use .aggregate_array to get a list of those properties for the entire image collection. To get the dates, don't forget that javascripts timestamp are in milliseconds.

Example:

from datetime import datetime

def reduce_bands(image) : 
   stats = image.select(['cloud','NDMI']) \
    .reduceRegion(reducer=ee.Reducer.mean(), geometry=buffer, scale=30)
   return image.set(stats) 

l8 = l8.map(reduce_bands) 
cloud = l8.aggregate_array('cloud').getInfo()
ndmi = l8.aggregate_array('NDMI').getInfo()
dates = l8.aggregate_array('system:time_start').getInfo()

# convert to datetime 
dates = [datetime.fromtimestamp(d//1000.) for d in dates]

where cloud ndmi and dates are list's.

1
  • that's exactly what I did, I wanted to wait until tomorrow to make an answer but you were faster. I'll wait to see if anyone come with another idea Jan 28, 2021 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.