1

When processing an ImageCollection in GEE my function drops the feature property system:time_start but leaves segmentStartTime. This means that I can't use ui.Chart.image.series to plot the data. This is really minor as I do plotting locally. However, I'm curious about how to add a new feature property with unique values to an ImageCollection.

As you can see in the code below, I tried using .set(). This didn't work. Any pointers?

var s1_collection = ee.ImageCollection('COPERNICUS/S1_GRD')
    .filterBounds(geometry)
    .filterDate('2020-01-29', '2020-09-1')
    .filter(ee.Filter.and(
      ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'),
      ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'),
      ee.Filter.eq('instrumentMode', 'IW')
    ));
print(s1_collection);

var addVVVH = function(image) {
  start = image.get('segmentStartTime')
  var VVVH = image.select('VV').divide(image.select('VH')).rename('VVVH')
  .copyProperties(image)
  .set('system:time_start', start);
  return image.addBands(VVVH);
};

var s1_collection2 = s1_collection.map(addVVVH);              
print(s1_collection2);

/////////
var panel = ui.Panel();
panel.style().set('width', '300px');

var intro = ui.Panel([
  ui.Label({
    value: 'Two Chart Inspector',
    style: {fontSize: '20px', fontWeight: 'bold'}
  }),
  ui.Label('Click point.')
]);
panel.add(intro);

var lon = ui.Label();
var lat = ui.Label();
panel.add(ui.Panel([lon, lat], ui.Panel.Layout.flow('horizontal')));

Map.onClick(function(coords) {
  lon.setValue('lon: ' + coords.lon.toFixed(2)),
  lat.setValue('lat: ' + coords.lat.toFixed(2));
  var point = ee.Geometry.Point(coords.lon, coords.lat);
  
  // Create S1 VV/VH chart
  var sentinelVVChart = ui.Chart.image.series(s1_collection2.select('VVVH'), point)
    .setChartType('ScatterChart')
    .setOptions({
      title: 'Sentinel backscatter (VV/VH)',
      trendlines: {0: {
        color: 'CC0000'
      }},
      lineWidth: 1,
      pointSize: 3,
    });
  panel.widgets().set(1, sentinelVVChart);
  
});

Map.style().set('cursor', 'crosshair');

ui.root.insert(0, panel);
Simon
  • 675
  • 1
  • 6
  • 15

1 Answers1

3

You almost got it right; it is needed to set the date after the return statement. Is this what you were aiming for?

var s1_collection = ee.ImageCollection('COPERNICUS/S1_GRD')
    .filterBounds(geometry)
    .filterDate('2020-01-29', '2020-09-1')
    .filter(ee.Filter.and(
      ee.Filter.listContains('transmitterReceiverPolarisation', 'VV'),
      ee.Filter.listContains('transmitterReceiverPolarisation', 'VH'),
      ee.Filter.eq('instrumentMode', 'IW')
    ));
print(s1_collection);

var addVVVH = function(image) {
  var VVVH = image.select('VV').divide(image.select('VH')).rename('VVVH')
  .copyProperties(image)
  return image.addBands(VVVH)
  .set({'system:time_start': image.get('segmentStartTime')});
};

s1_collection = s1_collection.map(addVVVH);              
print(s1_collection);

var chart = ui.Chart.image.series({
  imageCollection: s1_collection.select('VVVH'),
  region: geometry,
  reducer: ee.Reducer.mean(),
  scale: 10,
  xProperty: 'date'
})
print(chart)
NullDev
  • 6,739
  • 4
  • 30
  • 54
CrossLord
  • 574
  • 4
  • 20
  • That gets pretty close. I tried to tweak that to set image.time() / system:start_time: to the segmentStartTime property. I could set `time_start:` but not `system:time_start:` really close, but the extra colon doesn’t play well with the syntax – Simon Mar 24 '21 at 19:49
  • Ok. Surrounding system:time:start in quotes did the job. I’ll edit and accept. Thanks! – Simon Mar 24 '21 at 19:52