0

I'm trying to create a time series chart for SST and NDCI retrieving from Modis and Sentinel2 respectively by using the below code, but I get an error of No features contain non-null values of "system:time_start". How can I solve this problem?

var geometry = 
    /* color: #d63000 */
    /* shown: false */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[99.45287204043024, 13.987093052423877],
          [99.45287204043024, 11.662710322951911],
          [101.56224704043024, 11.662710322951911],
          [101.56224704043024, 13.987093052423877]]], null, false);
var sentinel2 = ee.ImageCollection("COPERNICUS/S2");
var modis = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI');

var ndci_viz = {
  bands: "NDCI",
  min:-1,
  max:1,
  palette: ['#22F7D4','#22D4F7','#70AFFF','#8761FF ','#F529FE']
};

var sst_viz = {
  bands: 'sst',
  min:10,
  max:50,
  palette: ['#396CFA','#4EE5F7','#EF6305','#E20806']
};

var S22017 = sentinel2.filterBounds(geometry)
               .filterDate('2017-01-01', '2017-12-31')
               .sort('CLOUDY_PIXEL_PERCENTAGE', false)
               .map(function (image){
                 return image.addBands(image.metadata('system:time_start'));
               })
               .mosaic()
               .clip(geometry); 

var S2water = s2_ndwi(S22017);
var ndci17 = ndci_algorithm(S2water);
Map.addLayer(ndci17.select('NDCI'), ndci_viz,"NDCI in 2017");

var modis2017 = modis.filterBounds(geometry)
               .filterDate('2017-01-01', '2017-12-31').select('sst')
               .mean()
               .clip(geometry);

Map.addLayer(modis2017, sst_viz, 'SST in 2017'); 



function s2_ndwi(img){
  //water mask
  var ndwi = img.normalizedDifference(['B3', 'B8']).rename('NDWI');
  return img.addBands(ndwi)
  .updateMask(ndwi.gt(0));
}

function ndci_algorithm(image){
  var ndci = image.expression(
    '((B5*sf) - (B4*sf))/((B5*sf) + (B4*sf))', {
      'B4': image.select('B4'),
      'B5': image.select('B5'),
      'sf': 0.0001
      
    }).rename('NDCI');
  return(ndci.rename('NDCI').set('system:time_start', image.get('system:time_start'))
  .set('CLOUDY_PIXEL_PERCENTAGE', image.get('CLOUDY_PIXEL_PERCENTAGE')));
}

var sstchart = ui.Chart.image.seriesByRegion({
  imageCollection: modis2017.select('sst'), 
  regions: geometry,
  reducer: ee.Reducer.mean(),
  scale: 50,
})
.setChartType('LineChart')
.setOptions({
      lineWidth: 1,
      pointSize: 3,
      title: 'SST Time Series',
      interpolateNulls: true,
      vAxis: {title: 'SST',titleTextStyle: {italic: false, bold: true}},
      hAxis: {title: 'Date',titleTextStyle: {italic: false, bold: true}},
    });
print('SST in 2017', sstchart);

var ndciChart = ui.Chart.image.seriesByRegion({
  imageCollection: ndci17.select('NDCI'), 
  regions: geometry,
  reducer: ee.Reducer.mean(),
  scale: 10,
})
.setChartType('LineChart')
.setOptions({
      lineWidth: 1,
      pointSize: 3,
      title: 'NDCI Time Series',
      interpolateNulls: true,
      vAxis: {title: 'SST',titleTextStyle: {italic: false, bold: true}},
      hAxis: {title: 'Date',titleTextStyle: {italic: false, bold: true}},
    });
print('NDCI in 2017', ndciChart);


1 Answer 1

0

In both of your mapped functions you need to copy the date onto your newly created image, using copyProperties.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.