I am trying to calculate an ee.Image()
object that contains the number of valid (= unmasked) pixels of a given Landsat ImageCollection. Originally I thought a simple ee.ImageColllection.count()
would do the job, but as the function treats each image independently of the observation date, the areas where the WRS rows in the Landsat tiles overlap are counted twice. My intention on the other hand is to retrieve a date dependent information of valid pixels.
Given that I have tried the following:
var imgCol_L8_SR = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(ROI)
.filter(ee.Filter.calendarRange(year_start,year_end,'year'))
.filter(ee.Filter.calendarRange(month_start,month_end,'month'))
.filter(ee.Filter.lt('CLOUD_COVER', cloud_cover))
.map(maskL8SR);
// initial Image in list
var ini =ee.List([
imgCol_L8_SR.select('B1').max()
.remap([0], [0], 0, "B1")
.rename('NOBS').int16()
]);
var fun_nobservations = function(date, previous) {
// Cast
date = ee.Date(date);
previous = ee.List(previous);
var filtered = imgCol_L8_SR.filterDate(date, date.advance(1,'day'));
// count valid observations per pixel:
var mask = ee.Image(filtered.count());
// set valid obs. in overlap back to 1:
mask = mask.where(mask.gt(1), 1);
var sum = mask.add(previous.get(-1));
return ee.Algorithms.If(filtered.size(), previous.add(sum), previous);
};
var start = ee.Date('1985-06-01');
var finish = ee.Date('2017-08-31');
var diff = finish.difference(start, 'day');
var range = ee.List.sequence(0, diff.subtract(1))
.map(function(day){return start.advance(day,'day')});
var nobs = ee.Image(ee.List(range.iterate(fun_nobservations, ini)).get(-1));
It counts the number of valid pixels dependent on the date and sums the single image layers iteratively in a list. The problem here is that given the study area size and the time-interval I run into a user memory exceeded error
.
Any ideas on how this could be approached differently?