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');