1

I want to create an average surface temperature time series chart (+ per year). However I am encountering this error Error generating chart: No features contain non-null values of "system:time_start".

I already added several .copyProperties(img, ['system:time_start']); but it doesn't seem to work.

Any ideas in fixing this?

// This example demonstrates the use of the Landsat 8 Collection 2, Level 2
// QA_PIXEL band (CFMask) to mask unwanted pixels.

function maskL8sr(image) {
  // Bit 0 - Fill
  // Bit 1 - Dilated Cloud
  // Bit 2 - Cirrus
  // Bit 3 - Cloud
  // Bit 4 - Cloud Shadow
  var qaMask = image.select('QA_PIXEL').bitwiseAnd(parseInt('11111', 2)).eq(0).copyProperties(image, ["system:time_start"]);
  var saturationMask = image.select('QA_RADSAT').eq(0);

  // Apply the scaling factors to the appropriate bands.
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2).copyProperties(image, ["system:time_start"]);
  var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(-124.15).copyProperties(image, ["system:time_start"]);

  // Replace the original bands with the scaled ones and apply the masks.
  return image.addBands(opticalBands, null, true)
      .addBands(thermalBands, null, true)
      .updateMask(qaMask)
      .updateMask(saturationMask)
      .copyProperties(image, ["system:time_start"]);
}

var months = ee.List.sequence(1, 12);
var years = ee.List.sequence(2016, 2021);

var byMonthYear = ee.ImageCollection.fromImages(
  years.map(function(y) {
    return months.map(function (m) {
      return collection
        .filter(ee.Filter.calendarRange(y, y, 'year'))
        .filter(ee.Filter.calendarRange(m, m, 'month'))
        .mean()
        .set('month', m).set('year', y);
  });
}).flatten());
print(byMonthYear)

// plot full time series
print(
  ui.Chart.image.series({
    imageCollection: byMonthYear,
    region: table,
    reducer: ee.Reducer.mean(),
    scale: 1000
  }).setOptions({title: 'SST over time'})
);

// plot a line for each year in series
print(
  ui.Chart.image.doySeriesByYear({
    imageCollection: byMonthYear,
    bandName:'sst',
    region: table,
    regionReducer: ee.Reducer.mean(),
    scale: 1000
  }).setOptions({title: 'SST for each year'})
);

access the code here:

1 Answer 1

1

Image collection byMonthYear doesn't have values of 'system:time_start'. For fixing this you have to do:

var byMonthYear = ee.ImageCollection.fromImages(
  years.map(function(y) {
    return months.map(function (m) {
      return collection
        .filter(ee.Filter.calendarRange(y, y, 'year'))
        .filter(ee.Filter.calendarRange(m, m, 'month'))
        .mean()
        .set('month', m).set('year', y).set('system:time_start', ee.Date.fromYMD(y, m, 1));
  });
}).flatten());

It is also necessary to use 'ST_B10' band name instead 'sst' in the second chart.

Complete code for an arbitrary geometry (your asset 'projects/ee-cczablan1/assets/NCR' is not accessible) is here.

After fixing these issues, running code in GEE code editor produces following result without any issue.

enter image description here

0

Your Answer

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

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