0

I am building a Landsat image collection time series and then trying to plot a time series of values for my region of interest by mean reduction. However, upon charting, I get an error message stating the image collection is empty. Why would the collection be empty?

Here is my code:

var Akdarya = ee.FeatureCollection("users/xodjayevshovkat/Akdarya_Crop_Class_Wheat_dissolve");

// Import S2 image collection.
var S2 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  // Filter collection.
  .filterDate('2018-01-01','2018-12-31')
  .filterBounds(Akdarya)
  .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 20);

// Define a cloud masking function.
var maskcloud1 = function(image) {
var QA60 = image.select(['QA60']);
  return image.updateMask(QA60.lt(1))//.clip(cotton);
};

// Define an index function (return only NDVI).
var NDVI = function(image) {
  return image.expression(
    '(NIR - RED) / (NIR + RED)', 
    {
      'NIR': image.select('B8'), 
      'RED': image.select('B4'), 
    }).rename('NDVI').copyProperties(image, image.propertyNames());
};

// Apply the cloud mask function.
var NDVIcol = S2.map(maskcloud1)
 // Apply the NDVI transformation.
 .map(NDVI);

// Calculate the per-pixel median NDRE for all images in collection.
var NDVImed = NDVIcol.median();

// Define vis params.
var NDVIvis = {
  palette: ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a', 
  '#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a',
  '#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a', 
  '#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a', 
  '#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a', 
  '#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a'],
  min: -0.5,
  max: 0.9};

// Plot a time series of 
var regions = Akdarya.toList(Akdarya.size())
var regionCount = Akdarya.size().evaluate(function (count) {
  for (var i = 0; i < count; i++) {
    var plotNDVI = ui.Chart.image.seriesByRegion({
      imageCollection:NDVIcol,
      regions: ee.FeatureCollection([ee.Feature(regions.get(i))]),
      reducer: ee.Reducer.mean(),  //median //mean
      xProperty: 'system:time_start',
      seriesProperty: 'Farmers'})
      .setChartType('LineChart').setOptions({
        title: 'NDVI Akdarya 2018',
        hAxis: {title: 'Date'},
        vAxis: {title: 'NDVI'},
    });
 print(plotNDVI);    
  }
})
// Display the results.
//print(plotNDVI);
Map.addLayer(NDVImed.clipToCollection(Akdarya), NDVIvis, 'NDVI');
  • 2
    Hi! In the future please be sure to: 1) Include a little more info in the body of the question to provide context; 2) format your script as a code block; 3) share any imported assets so that others can reproduce the problem - alternatively mock up an example that uses toy geometries and/or public data from the Catalog. – Justin Braaten Feb 11 at 19:38
3

Generally, if a collection is empty it is because applied filters are too restrictive and no collection elements pass. In this case it is because you are filtering by the "CLOUDY_PIXEL_PERCENTAGE" property, which does not exist for the "LANDSAT/LC08/C01/T1_TOA" collection (it is for Sentinel-2) so no images pass the conditional test.

I can't replicate your example because your imported asset is not publicly shared. I've mocked up an example that illustrates the issue with filtering by the incorrect cloud cover property.

// Filter by 'CLOUDY_PIXEL_PERCENTAGE' property.
var col = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  .filterBounds(ee.Geometry.Point(-120.6, 37.6))
  .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 20);

print("Filter by 'CLOUDY_PIXEL_PERCENTAGE' property", "Collection size", col.size()); 

// Filter by 'CLOUD_COVER' property.
var col = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  .filterBounds(ee.Geometry.Point(-120.6, 37.6))
  .filterMetadata('CLOUD_COVER', 'less_than', 20);

print("Filter by 'CLOUD_COVER' property", "Collection size", col.size());
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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