I'm new to Earth Engine and struggling with a problem related to ee.Date
formats. I am filtering image collections to pass into later analyses, including regression. However, when I later try to add a time band, to permit that regression, I receive errors. We've tracked this down to the way we have defined system:time_start
being wrong in the monthly filtering, because our code pulls the system:time_start
in date format but really it should be the time stamp in milliseconds since the UNIX epoch.
Here is the code we are using to create our monthly composites:
var interval = 1;
var month_list = ee.List.sequence(1,12, interval);
var year_list = ee.List.sequence(2000, 2014);
var monthlyCHIRPS = ee.ImageCollection.fromImages(
year_list.map(function (ynz) {
return month_list.map(function(mnz){
var w = CHIRPSCollection.filter(ee.Filter.calendarRange(ynz, ynz, 'year'))
.filter(ee.Filter.calendarRange(mnz, ee.Number(mnz).add(interval), 'month'))
.sum();
return w.set('year', ynz)
.set('month', mnz)
.set('date', ee.Date.fromYMD(ynz,mnz,1))
.set('system:time_start',ee.Date.fromYMD(ynz,mnz,1))
.set('ID',ee.Date.fromYMD(ynz,mnz,1))
})
}).flatten())
print(monthlyCHIRPS, 'Monthly CHIRPS');
I believe the error is in setting the system:time_start, in that currently we pull the date from YMD, in the same format. What I want to do, is somehow pull the date, but convert it back into a UNIX timestamp as in the original images, so I can later add a timeband.
Does anyone know how I can correct this code to do that, or have an alternative code for creating monthly composites that would permit this?