Google Earth Engine – Create Time Series for Multi-Polygon in Google Earth Engine

featuresgoogle-earth-enginegoogle-fusion-tablestime series

I have a imported a KML as fusion table to GEE. This fusion table is type of FeatureCollection and contains 6 elements. I would like to create a time series of a raster (in this example MODIS LST), based on the feature. Meaning, my final goal is to get a chart (which I can export as csv), where the x-axis is the date and the y-axis is LST (or other raster value), per each feature in the feature collection, or one that contains all, which I can differentiate between them. I saw the GEE example script – Image Time Series By Region, but when I changed the feature collection there to my fusion table, I got one chart for all of my features, I assume this is the average of all of them.

What I got so far is this:

// Get  temperature data for 1 year.
var modis = ee.ImageCollection('MODIS/006/MOD11A1');
var modisLST = modis.filterBounds(fc2)
                    .filterDate('2003-12-25', '2008-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(), fc2).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'}}));

where fc2 is my fusion table that contains 6 features.
How can I accomplished my goal?

Best Answer

As this is a common operation, there's a function to do it in one go, so you don't have to do your own multi-temporal aggregation: ui.Chart.image.seriesByRegion.

var modis = ee.ImageCollection('MODIS/006/MOD11A1');
var modisLST = modis.filterBounds(fc2)
                    .filterDate('2003-12-25', '2004-02-25')
                    .select('LST_Day_1km');

// Convert temperature to Celsius.
modisLST = modisLST.map(function(img){
  return img.multiply(0.02).subtract(273.15).copyProperties(img, ['system:time_start'])
});

// Create a graph of the time-series.
var graph = ui.Chart.image.seriesByRegion({
  imageCollection: modisLST, 
  regions: fc2, 
  reducer: ee.Reducer.mean()
})
print(graph)

If you click on the box in the upper right corner of the chart, you can download the CSV used to generate the chart.

If, for some reason, you still want to do your own aggregation, you should use reduceRegions to reduce each region separately. The way you're doing it with reduceRegion, you are indeed getting the mean of all the regions. The downside of doing it yourself is that you then have to rearrange the results into something the charting API can understand.

Related Question