Skip to content

Latest commit

 

History

History
96 lines (87 loc) · 3.19 KB

10.time_series.md

File metadata and controls

96 lines (87 loc) · 3.19 KB

10. Images Compositing and Time series

https://code.earthengine.google.com/0aab36f0d920a0e9d294f72d9c6012e6

Objective

  • Yearly, seasonal, monthly, decadal time series (NDVI)

General Information

Core script

  • Define initial conditions
var hls_col = ee.ImageCollection('users/ndminhhus/eLEAF/nt/hls_v01').map(ndviF);
var paddy_nt = ee.Image('users/ndminhhus/NTmask/paddy');
var geometry = ee.Geometry.Point([108.94553918036411,11.566755394830713])
//function ndvi
function ndviF(img){
  var ndvi = img.normalizedDifference(['nir','red']).rename('NDVI');
  return img.addBands(ndvi)
}
  • Seasonal Composite
var years = ee.List.sequence(2018, 2019)
var seasonalNDVI =  ee.ImageCollection.fromImages(
  years.map(function (y) {
  var w =  hls_col.filter(ee.Filter.calendarRange(y, y, 'year'))
          //spring crop (Jan -> Apr), summer crop (May to Aug), rainy season (Sep to Dec)
          .filter(ee.Filter.calendarRange(1, 4, 'month'))
          // .filter(ee.Filter.calendarRange(5, 8, 'month'))
          // .filter(ee.Filter.calendarRange(9, 12, 'month'))
          .mean();
  return w.set('year', y)
          .set('system:time_start',ee.Date.fromYMD(y,1,1));
}).flatten());
print(seasonalNDVI)
  • Monthly Composite
var months = ee.List.sequence(1,12);
var monthlyNDVI =  ee.ImageCollection.fromImages(
  months.map(function(m){
  var w = hls_col.select('NDVI').filter(ee.Filter.calendarRange(m, m, 'month'))
           .mean();
  return w.set('year', 2018)
           .set('month', m)
           .set('date', ee.Date.fromYMD(2018,m,1))
           .set('system:time_start',ee.Date.fromYMD(2018,m,1)) 
 
}).flatten());
print(monthlyNDVI)
  • Decadal Composite
var start = '2018-01-01';
var end = '2018-12-31';
var interval = 10;
var increment = 'day';
var start = start; 
// make a list 
var startDate = ee.Date(start);
var secondDate = startDate.advance(interval, increment).millis();
var increase = secondDate.subtract(startDate.millis());
var list = ee.List.sequence(startDate.millis(), ee.Date(end).millis(), increase);
var tenDays =  ee.ImageCollection.fromImages(list.map(function(date){
  return hls_col.select('NDVI')
                .filterDate(ee.Date(date), ee.Date(date).advance(interval, increment))
                //.min() //take the darkest pixel from L7, L8 or S2. reduce cloud contamination
                .mean()
                .set('system:time_start',ee.Date(date).millis());
}));
print(tenDays,'tenDays');

Visualization and Checking

  • Time Series
// Predefine the chart titles.
var title = {
  title: ' NDVI Series ',
  hAxis: {title: 'Date'},max:1,
  vAxis: {title: 'NDVI'},
  series: {0:{color:'red'},1:{color:'blue'}},
};

var chart_ndvi_season = ui.Chart.image.series(seasonalNDVI.select('NDVI'), geometry, ee.Reducer.mean(), 30).setOptions(title).setChartType('ScatterChart');
print(chart_ndvi_season)

var chart_ndvi_10days = ui.Chart.image.series(tenDays.select('NDVI'), geometry, ee.Reducer.mean(), 30).setOptions(title).setChartType('ScatterChart');
print(chart_ndvi_10days)

  • Decadal (10 days) composite images timeseries decadal

References