I'm trying to replicate this python script to calculate NDVI mean for a feature collection (Get results in an Earth Engine python script). It seems like the code calculates a result, but a cant see result. This is the code:
import datetime
import ee
ee.Initialize()
#Feature collection
fc = ee.FeatureCollection("ft:1x290vohty0Wgdn5jL3RlpzryK7dfOPtG6yY213e0");
fc_filtered = fc.filter(ee.Filter.equals('NUM_DECS', 1))
#Image collection
Sentinel_collection = (ee.ImageCollection('COPERNICUS/S2')
.filterBounds(fc_filtered)
.filterDate(ee.Date('2017-01-01'),ee.Date('2017-08-01')))
def GetSeries(feature):
def NDVIcalc(img):
red = img.select('B4')
nir = img.select('B8')
ndvi = nir.subtract(red).divide(nir.add(red)).rename(['NDVI'])
return (feature
.set(ndvi.reduceRegion(ee.Reducer.mean(), feature.geometry(), 10))
.set('date', img.date().format("YYYYMMdd")))
series = Sentinel_collection.map(NDVIcalc)
list = series.reduceColumns(ee.Reducer.toList(2), ['date', 'NDVI']).get('list')
return feature.set(ee.Dictionary(ee.List(list).flatten()))
result = fc_filtered.map(GetSeries)
print(result.getInfo())
Give me this result:
{'columns': {}, 'type': 'FeatureCollection', 'features': [], 'properties': {'name': 'kmltest', 'DocID': '1x290vohty0Wgdn5jL3RlpzryK7dfOPtG6yY213e0'}}
So it does not looks like something is coming out of it?
I havent yet tried the next where the following is included:
# Get all possible dates.
dates = ee.List(Sentinel_collection.map(function(img) {
return ee.Feature(null, {'date': img.date().format("YYYYMMdd") })
}).aggregate_array('date'))
# Make a default value for every date.
header = ee.Feature(null, ee.Dictionary(dates, ee.List.repeat(-1, dates.size())))
output = header.merge(result)
ee.batch.Export.table.toDrive(...)
Any suggestions for what a do wrong? Will prefer to have the result in the feature collection or exported as a list.