2

Recently I've been trying to print time series for different regions and show them in the same plot. Everything goes fine if I exclude the 4th region into the time series (1-3 time series are fine). But when I add the 4th region, time series points at other locations are gone. The output plot only shows the time series of the last region (only remains 2 points of other regions).

So the problem is: how to add the time series of the 4th region into the plot?

Excluding the 4th region in the feature collection would work properly, but I don't want to omit it.

Here's the link to the code.

var timeField = 'system:time_start';
// Define test regions.
var regions = ee.FeatureCollection([    // Test Regions are in Hunan, China.
  ee.Feature(    // Region 1
    ee.Geometry.Rectangle(113.201806473291, 27.6867096858736, 113.251537728778, 27.7276180415286), {label: 'Region1'}),
  ee.Feature(  // Region 2
    ee.Geometry.Rectangle(113.152404668942, 27.6389241071109, 113.177553060666, 27.6780758597365), {label: 'HengJiangCun'}),
  ee.Feature(  // Region3
    ee.Geometry.Rectangle(113.196381164761, 27.7769042331009, 113.216382570871, 27.7999150021881), {label: 'ChenJiaBa'}),
  ee.Feature(  // Region4 Adding this region would omit most of the points
    ee.Geometry.Rectangle(113.038857564920, 27.9581880215077, 113.042355165475, 27.9719283228899), {label: 'ZhaoShanXiang'}),
]);

// Add base maps.
Map.addLayer(regions, {}, 'Test Regions'); // Layer: Test Regions.
print(regions)

// Load Sentinel-2 TOA reflectance data.
var masked = S2                                 
    .filterDate('2017-01-01', '2017-12-31')
    .filterBounds(regions);
print(masked);

// Function to calculate NDVI in S2 images.
function S2NDVI(image){
  var bands = image.select('B4','B8');
  var NDVI = bands.expression('(b(1)-b(0))/(b(0)+b(1))').select(['B8'],['NDVI']);
  //return NDVI;
  return image.addBands(NDVI);
}

// Calculate S2 NDVI.
var S2VI = masked.map(S2NDVI);
print(S2VI);

// Generating 25 percentile time series chart.
var reducer = ee.Reducer.percentile([25]);

// Time series chart settings.
var TSChart = ui.Chart.image.seriesByRegion(
    S2VI.select('NDVI'), regions, reducer, 'NDVI', 20, 'system:time_start','label')
        .setChartType('ScatterChart')
        .setOptions({
          title: 'CI-Red Edge time series at 4 regions',
          vAxis: {title: 'CI Red Edge'},
          lineWidth: 1,
          pointSize: 4,
          series: {
            0: {color: '008744'}, // Region 1
            1: {color: '0057e7'}, // Region 2
            2: {color: 'd62d20'},  // Region 3
            3: {color: 'ffa700'}, //Region 4
}});

print(TSChart);
Map.addLayer(S2VI.select('NDVI'),{},'Sentinel VI Collection');
2
  • 1
    Please Edit your question to contain code, so that when the link on the third-party site fails, the question body will not be damaged.
    – Vince
    Nov 27, 2018 at 1:49
  • Have you tried adding a 5th region and see how that interacts with the other 4?
    – whyzar
    Nov 27, 2018 at 18:33

1 Answer 1

2

This problem is similar to something I discovered. It doesn't seem good to filter an image collection on a feature collection with multiple geometries. Instead, you should use filterBounds on just one geometry, for example a point or rectangle.

I guess this has something to do with the Sentinel-2 colleciton, in which every image is divided into multiple (I think 4) granules (or 'tiles'). You will see that your image collection now consist of about 62 images, so almost 4 times less images.

When I add the following to your code, it returns the graph you probably will have expected. The point is in the middle of your four regions.

// add a point
var point = ee.Geometry.Point([113.16010429074402, 27.739383729419057]);

// Load Sentinel-2 TOA reflectance data.
var masked = S2                                 
    .filterDate('2017-01-01', '2017-12-31')
    .filterBounds(point);
print(masked);

Link to the code: https://code.earthengine.google.com/717ec998129ee7afba4e2395f1ef5edf

The new Graph

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.