I'd like to sample points from temporal Sentinel-2 images covering a state, about 13 month's mosaic image were stacked into a new image. When I sampled points on the image, I got nothing. I think maybe some null or masked points led this case. I wonder is there a good solution?
//Load state borders from assets
var studyArea = ee.Feature(ee.FeatureCollection('ft:17aT9Ud-YnGiXdXEJUyycH2ocUqreOeKGbzCkUw')
.filter(ee.Filter.eq('id', 'MO'))
.first()).getInfo().geometry;
var start = ee.Date('2017-01-01');
var finish = ee.Date('2017-12-31');
// Map the function over one year of data and take the median. // Load Sentinel-2 TOA reflectance data.
var s2col = ee.ImageCollection('COPERNICUS/S2')
.filterDate(start, finish)
.filterBounds(studyArea)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30));
// Difference in days between start and finish
var diff = finish.difference(start, 'day')
print(diff)
var temporalResolution = 30 // days
// Make a list of all dates
var range = ee.List.sequence(0, diff.subtract(1), temporalResolution).map(function(day){return start.advance(day,'day')})
print('range',range)
// Function for iteraton over the range of dates
var day_mosaics_s2 = function(date, newlist)
{
date = ee.Date(date)
newlist = ee.List(newlist)
var filtered = s2col.filterDate(date, date.advance(temporalResolution, 'day'))
var image = ee.Image(filtered.mosaic().clip(studyArea)
.select('B2','B3','B4','B5','B6','B7','B8','B8A','B11','B12'));
return ee.List(ee.Algorithms.If(filtered.size(), newlist.add(image), newlist))
}
var news2col = ee.ImageCollection(ee.List(range.iterate(day_mosaics_s2, ee.List([]))));
print('mosaicImageCollection_s2',news2col);
var stackCollection = function(collection)
{
var first = ee.Image(collection.first()).select([]);
var appendBands = function(image, previous)
{
return ee.Image(previous).addBands(image);
};
return ee.Image(collection.iterate(appendBands, first));
};
var stacked_s2 = stackCollection(news2col);
print('stacked_composite bands', stacked_s2.bandNames());
var training = stacked_s2.sample(
{
numPixels: 500,
scale:10,
seed: 0
}
);
print('samples',training)