0

I have a points feature collection and have added the latitude and longitude to each point's properties as well. Now I want to do a processing on each point and want to use the map function. The processing function will extract some Landsat 8 time series and do an analysis, and the analysis subfunction should be fed with the parameters in a dictionary format and will return a dictionary.

def getModel(pointFeature):
    args = pointFeature.toDictionary()
    lon = args.get('longitude')
    lat = args.get('latitude')
    point = ee.Geometry.Point([lon, lat])
    # Create image collection
    l8_collection = ee.ImageCollection(
        'LANDSAT/LC08/C01/T1_SR').filterBounds(point).filterDate('2015-01-01', '2018-01-01')
    info = l8_collection.getRegion(point, 30).getInfo()
    header = info[0]
    data = np.array(info[1:])
    results = analysis_function(header, data)
    return ee.Feature(None, results)

Results = points.map(getModel)

But I get the below error and it traces to the line info = l8_collection.getRegion(point, 30).getInfo():

ee.ee_exception.EEException: Failed to decode JSON.
Error: Field 'value' of object '{"type":"ArgumentRef","value":null}' is missing or null.
Object: {"type":"ArgumentRef","value":null}.

I think it is all about client/server variable passing in GEE, but I couldn't manage to solve it. I tried to add getInfo() after calculations of Lat and Lon or casting the Lat and Lon to ee.Number() but the problem persists. Any help?

0

You cannot use getInfo() inside a map function. Also, you cannot create a numpy array inside a map function. So this is leading nowhere. I'd do something like this:

def getModel(pointFeature, ini_list):
    args = pointFeature.toDictionary()
    lon = args.get('longitude')
    lat = args.get('latitude')
    point = ee.Geometry.Point([lon, lat])
    # Create image collection
    l8_collection = ee.ImageCollection(
        'LANDSAT/LC08/C01/T1_SR').filterBounds(point).filterDate('2015-01-01', '2018-01-01')
    info = l8_collection.getRegion(point, 30)
    return ee.List(ini_list).add(info)

info_list = ee.List(points.iterate(getModel, ee.List([]))

feat_list = []
for point_data in info_list.getInfo(): 
    header = point_data[0]
    data = np.array(point_data[1:])
    results = analysis_function(header, data)
    feat_list.append(ee.Feature(None, results))

Results = ee.FeatureCollection(feat_list)

The approach would be different if analysis_function would be a function made entirely in Earth Engine.

  • Many thanks for your reply. Yes I see my mistake. But the analysis function is an imported one and I can not change or rewrite it. So because I should use a for loop anyway and it is the analysis part that takes time, there is no point is using map or iterate techniques in my case. Right? – Shahriar49 Mar 19 at 16:26
  • If analysis_function doesn't use Earth Engine API functions but local libraries then no, you won't be able to call it from inside a map function. You could try to "translate" that function to use only EE API, then you could use it in a map function, and you'd probably save a lot of time – Rodrigo E. Principe Mar 20 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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