I have a script that allows me to obtain a CSV file containing the time series of monthly MODIS NDVI values for several points. The problem here is that the CSV file I get is organized like this:
ID Mean date
P1 xxx year1/month1
P2 xxx year1/month1
P3 xxx year1/month1
. . . . .
P1 xxx year1/month2
P2 xxx year1/month2
P3 xxx year1/month2
However, I would prefer to have a structure where each cologne is the average NDVI value of each point and each line is the date:
date P1 P2 P3
year1/month1 xxx xxx xxx
year1/month2 xxx xxx xxx
Here is the code:
var ptsTopo = ee.FeatureCollection(point)
// var modis= ee.ImageCollection("MODIS/006/MOD13Q1");
// var dataset=ee.ImageCollection(modis.filterDate('2006-01-01', '2016-12-31').select('NDVI'));
var modis = ee.ImageCollection("MODIS/006/MOD13Q1")
.select('NDVI')
.filterDate('2006-01-01','2016-12-31')
.map(function(img){var d = ee.Date(ee.Number(img.get('system:time_start')));
var m = ee.Number(d.get('month'));
var y = ee.Number(d.get('year'));
return img.set({'month':m, 'year':y});
});
var months = ee.List.sequence(1, 12);
var start_year = 2006;
var start_date = '2006-01-01';
var end_year = 2016;
var end_date = '2016-12-31';
var years = ee.List.sequence( start_year, end_year);
var byYearMonth = ee.ImageCollection.fromImages(
years.map(function(y){
return months.map(function(m){
return modis.filterMetadata('year', 'equals', y)
.filterMetadata('month', 'equals', m)
.select('NDVI').mean()
.set('year', y)
.set('month', m)
.set('date', ee.Date.fromYMD(y,m,1));
});
}).flatten()
);
var proj = ee.Image(modis.first()).projection()
var NDVI_pts = byYearMonth.map(function(img){
var features = ptsTopo.map(function(f) {return f.set('date', img.get('date'))})
return img.reduceRegions(features, ee.Reducer.mean(), 500, proj);
}).flatten();
print(NDVI_pts.limit(10));
Export.table(NDVI_pts, 'NDVI_pts', {fileFormat: 'CSV'});