I am struggling to convert a javascript earth engine routine to python which is taken from this material here
The javascript is as follows I have included the input collections for context.
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(roi)
.filterDate('2016-01-01', '2016-12-31');
// Load an Earth Engine table.
var blocks = ee.FeatureCollection('TIGER/2010/Blocks');
var subset = blocks.filterBounds(roi);
print('Size of Census blocks subset', subset.size()); // 409
var triplets = l8.map(function(image) {
return image.select('B1').reduceRegions({
collection: subset.select(['blockid10']),
reducer: ee.Reducer.mean(),
scale: 30
}).filter(ee.Filter.neq('mean', null))
.map(function(f) {
return f.set('imageId', image.id());
});
}).flatten();
The part I am a bit stuck on is the conversion of the variable triplets
, which includes various nested routines. My python version returns the error:
Unrecognized argument type to convert to a FeatureCollection: {'collection': <ee.featurecollection.FeatureCollection object at 0x7f29fb0e2b80>, 'reducer': <ee.Reducer object at 0x7f29fb10e670>, 'scale': 30}
The issue seems to be map(imfunc), which I assume is down to me getting the python function wrong.
def imfunc(image):
return image.select('B1').reduceRegions({
'collection': subset.select(['blockid10']),
'reducer': ee.Reducer.mean(),
'scale': 30})
def wrapf(f):
return f.set('imageId', image.id())
triplets = l8.map(imfunc).filter(ee.Filter.neq('mean', {})).map(wrapf).flatten()
Can anyone shed light on where I am going wrong with the python conversion?