Following code produces a monthly aggregation for maximum 2 meters air temperature, in Kelvin degrees, by using a point reduce region with Image Collection "ECMWF/ERA5/DAILY". Results are identical to those obtained with daily series running an external developed python code. However, below code also has a commented portion destined to convert Kelvin to Celsius degrees. It was adapted based in Create time series and export it to csv GEE answer.
var fg_points = ee.Geometry.Point (-70.2166985,-38.5275513); //p18
// Set years and month
var startYear = 1981;
var endYear = 2014;
var years = ee.List.sequence(startYear, endYear);
var months = ee.List.sequence(1,12);
// load the image collection
var Daily = ee.ImageCollection("ECMWF/ERA5/DAILY")
.select('maximum_2m_air_temperature');
// Convert Kelvin to Celsius degrees
//Daily = Daily.map(function(img){
// var date = img.get('system:time_start');
// return img.subtract(273.15).set('system_time_start', date);
//});
// make monthly mean mosaics
// loop over the years and months to get summed monthly images
var byMonth = ee.ImageCollection(ee.FeatureCollection(years.map(function(y){
var yearCollection = Daily.filter(ee.Filter.calendarRange(y, y, 'year'));
var byYear = ee.ImageCollection.fromImages(
months.map(function(m) {
var maxImage = yearCollection.filter(ee.Filter.calendarRange(m, m, 'month'))
.reduce(ee.Reducer.mean());
var date = ee.Date.fromYMD(y, m, 1).format("MM_dd_YYYY");
return maxImage.set('system:time_start', ee.Date.fromYMD(y, m, 1)).rename(date);
//.set('month', m).set('year', y); // eventually set year and month
}));
return byYear;
})).flatten());
print(byMonth);
// filter the empty one out
var outputMonthly = byMonth.filter(ee.Filter.listContains('system:band_names', 'constant').not())
.sort('system:time_start').toBands();
print(outputMonthly);
var features = outputMonthly.reduceRegions(fg_points, ee.Reducer.first(), 30);
//print(features);
Export.table.toDrive(features,
"temp_max_mean",
"GEE_Folder",
"temp_max_mean_monthly_p");
When I uncomment code portion above referred:
.
.
.
// Convert Kelvin to Celsius degrees
Daily = Daily.map(function(img){
var date = img.get('system:time_start');
return img.subtract(273.15).set('system_time_start', date);
});
.
.
.
for producing monthly series in Celsius degrees, I got following error message:
ImageCollection.reduce: Can't apply calendarRange filter to objects without a timestamp
A similar message is obtained in a tasks Tab:
Error: ImageCollection.reduce: Can't apply calendarRange filter to objects without a timestamp.
Recently, I found out this function:
// Convert Kelvin to Celsius degrees
Daily = Daily.map(function(img){
var start = ee.Date(img.get('system:time_start'));
var end = ee.Date(img.get('system:time_end'));
var label = start.format('YYYY-MM-dd').cat(' - ').cat(end.format('YYYY-MM-dd'));
return img.subtract(273.15).set({label: label});
});
and it produces same error message. Nor does it add a timestamp.
So, How can I add a timestamp in a new Image Collection obtained from a native GEE Image Collection for producing images subtracted by a determined factor in a monthly aggregation?