Google Earth Engine (GEE) - Error No features contain non-null values of “system:time_start“ when loading graph.

 

mistake:

Error generating chart: The image collection is empty.


No features contain non-null values of "system:time_start".


The image collection is empty.

Original code:


var geometry = /* color: #d63000 */ee.Geometry.Polygon(
        [[[-81.14573791618602, 25.335453210591712],
          [-80.90953186149852, 25.32924702619973],
          [-81.03312805290477, 25.5190118912932],
          [-81.1992962657954, 25.50537864099872]]]),
    Mang = ee.FeatureCollection("users/selenachav5/mangrove_vector");
var WSC1050 = /* color: #98ff00 */ee.Geometry.Point([-81.11963534, 25.42344856]);

var mask = Mang
var mangroveImg = ee.Image(0).paint(mask, 1);
Map.addLayer(mangroveImg, {min:0, max:1}, 'mangroveImg')
function maskNonMangrove(i){
  return i.updateMask(mangroveImg).copyProperties(i);
}

var col = ee.ImageCollection('MODIS/061/MOD13Q1')
                  .map(function(im) {return im.select(['NDVI']).multiply(0.0001)})
                  .filter(ee.Filter.date('2013-01-01', '2023-05-01'))
                  .map(maskNonMangrove) 
                  ;




var ndvi = col.select('NDVI');
var ndviVis = {
  min: 0.0,
  max: 8000.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(ndvi, ndviVis, 'NDVI');

var ndviChart = ui.Chart.image.series(ndvi, WSC1050, ee.Reducer.mean(), 250);
  ndviChart.setOptions({
    title: 'MODIS NDVI',
    vAxis: {title: 'NDVI', maxValue: 9000},
    hAxis: {title: 'date', format: 'MM-yy', gridlines: {count: 7}},
  });
  
print(ndviChart)

Parse:

The main reason for this is that when we map and calculate the image set, something that covers up the time attribute appears, so we need to add the attribute after performing the mapping function, that is, copy the retrograde attribute, so as to retain this Time attribute, because in the default state, the time attribute needs to be loaded as the horizontal axis in the chart, so here we must retain the original image time information.

key code:

.copyProperties(i,['system:time_start'])

Chart functions:

ui.Chart.image.series(imageCollection, region, reducerscalexProperty)

Generates a Chart from an ImageCollection. Plots derived values of each band in a region across images. Usually a time series.

  • X-axis: Image, labeled by xProperty value.

  • Y-axis: Band value.

  • Series: Band names.

Returns a chart.

Arguments:

imageCollection (ImageCollection):

An ImageCollection with data to be included in the chart.

region (Feature|FeatureCollection|Geometry):

The region to reduce.

reducer (Reducer, optional):

Reducer that generates the values for the y-axis. Must return a single value. Defaults to ee.Reducer.mean().

scale (Number, optional):

Scale to use with the reducer in meters.

xProperty (String, optional):

Property to be used as the label for each image on the x-axis. Defaults to 'system:time_start'.

Returns: ui.Chart

Modified code:

var WSC1050 = /* color: #98ff00 */ee.Geometry.Point([-81.11963534, 25.42344856]);

var mask = Mang
var mangroveImg = ee.Image(0).paint(mask, 1);
Map.addLayer(mangroveImg, {min:0, max:1}, 'mangroveImg')
function maskNonMangrove(i){
  return i.updateMask(mangroveImg).copyProperties(i,['system:time_start']);
}

var col = ee.ImageCollection('MODIS/061/MOD13Q1')
                  .map(function(i) {return i.select(['NDVI']).multiply(0.0001).copyProperties(i,['system:time_start'])})
                  .filter(ee.Filter.date('2013-01-01', '2023-05-01'))
                  .map(maskNonMangrove) 
                  ;


var ndvi = col.select('NDVI');
var ndviVis = {
  min: 0.0,
  max: 8000.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};
Map.setCenter(6.746, 46.529, 2);
Map.addLayer(ndvi, ndviVis, 'NDVI');

var ndviChart = ui.Chart.image.series(ndvi, WSC1050, ee.Reducer.mean(), 250);
  ndviChart.setOptions({
    title: 'MODIS NDVI',
    vAxis: {title: 'NDVI', maxValue: 1},
    hAxis: {title: 'date', format: 'MM-yy', gridlines: {count: 7}},
  });
  
print(ndviChart)

 

Guess you like

Origin blog.csdn.net/qq_31988139/article/details/131252085