Google Earth Engine – How to Create Time Series and Export to CSV

csvgoogle-earth-enginetime series

I'm new to GEE and I'm trying to create time series of MODIS LST for a selected point. I first chose a point on the map and my script is:

var POI = geometry;
// Get  temperature data for 1 year.
var modis = ee.ImageCollection('MODIS/006/MOD11A1');
var modisLST = modis.filterBounds(POI)
    .filterDate('2003-12-25', '2004-02-25')
    .select('LST_Day_1km');

// Convert temperature to Celsius.
modisLST = modisLST.map(function(image) {
  return image.multiply(0.02).subtract(273.15);
});

var tempTimeSeries = ui.Chart.image.seriesByRegion({
  imageCollection: modisLST,
  regions: POI,
  reducer: ee.Reducer.mean(),
  xProperty: 'system:time_start',
  seriesProperty: 'label'
});

When I run this script, nothing happens and after 2 minutes I get:

Too many concurrent aggregations

How do I export the time series from here to csv or xlsx files? and also (but not super important) how do I display it on the GEE platform.

Best Answer

Here is a working script (https://code.earthengine.google.com/ea82c9501fb736f3f615741620f4875a):

// Get  temperature data for 1 year.
var modis = ee.ImageCollection('MODIS/006/MOD11A1');
var modisLST = modis.filterBounds(POI)
                    .filterDate('2003-12-25', '2004-02-25')
                    .select('LST_Day_1km');


// Convert temperature to Celsius.
modisLST = modisLST.map(function(img){
  var date = img.get('system:time_start');
  return img.multiply(0.02).subtract(273.15).set('system_time_start', date);
});

// Create a function that takes an image, calculates the mean over a
// geometry and returns the value and the corresponding date as a 
// feature.
var createTS = function(img){
  var date = img.get('system_time_start');
  var value = img.reduceRegion(ee.Reducer.mean(), POI).get('LST_Day_1km');
  var ft = ee.Feature(null, {'system:time_start': date, 
                             'date': ee.Date(date).format('Y/M/d'), 
                             'value': value});
  return ft;
};

// Apply the function to each image in modisLST.
var TS = modisLST.map(createTS);

// Create a graph of the time-series.
var graph = ui.Chart.feature.byFeature(TS, 'system:time_start', 'value');

print(graph.setChartType("ColumnChart")
           .setOptions({vAxis: {title: 'LST [deg. C]'},
                        hAxis: {title: 'Date'}}));

// Export the time-series as a csv.
Export.table.toDrive({collection: TS, selectors: 'date, value'});

Basically what's happening is that we map over the images in the image-collection, and create a feature for each image (without a geometry). Then we use the feature-collection to export a csv and plot a graph.