I am trying to compute the NDVI index using the MODIS Landset in Python and to visualize it in a time series chart, but I am facing an error and I cannot understand where is the problem. This is my code:
campo_1= ee.Geometry.Polygon(
[[10.6552805, 45.0993966],
[10.6584562, 45.0978214],
[10.6608595, 45.1003054],
[10.6576837, 45.1019109],
[10.6552805, 45.0993966]]])`
campo1_points= ee.FeatureCollection.randomPoints(campo_1, 8).geometry()
def create_reduce_region_function(geometry,
reducer=ee.Reducer.mean(),
scale=1000,
crs='EPSG:4326',
bestEffort=True,
maxPixels=1e13,
tileScale=4):
def reduce_region_function(img):
stat = img.reduceRegion(
reducer=reducer,
geometry=geometry,
scale=scale,
crs=crs,
bestEffort=bestEffort,
maxPixels=maxPixels,
tileScale=tileScale)
return ee.FeatureCollection(geometry, stat).set({'millis': img.date().millis()})
return reduce_region_function
def fc_to_dict(fc):
prop_names = fc.first().propertyNames()
prop_lists = fc.reduceColumns(
reducer=ee.Reducer.toList().repeat(prop_names.size()),
selectors=prop_names).get('list')
return ee.Dictionary.fromLists(prop_names, prop_lists)
date_range= ee.DateRange('2023-07-24','2023-07-31')
ndvi = ee.ImageCollection('MODIS/006/MOD13A2').filterDate(date_range).select('NDVI')
reduce_ndvi = create_reduce_region_function(
geometry=campo1_points, reducer=ee.Reducer.mean(), scale=1000, crs='EPSG:3310')
ndvi_stat_fc = ee.FeatureCollection(ndvi.map(reduce_ndvi)).filter(
ee.Filter.notNull(ndvi.first().bandNames()))
fc_to_dict(ndvi_stat_fc).getInfo()
When trying to get the features of the variable I got the following error:
EEException: Image.bandNames: Parameter 'image' is required.
Can someone explain to me why and how to fix this error?