I would like to export monthly temperature from TerraClimate, But instead of getting the 12 months period It has index of 9rows and from the year that I desire from 1995 to 2020 I got only until 2004. This is very confusing to me as I am new to Google Earth Engine. This also some modification from any post but I couldn't track from where.
//var geometry = ee.Point([76.50672654438921,35.35824030837368]);
var fg_points = geometry;
// Set years and month
var startYear = 1995;
var endYear = 2020;
var years = ee.List.sequence(startYear, endYear);
var months = ee.List.sequence(1,12);
// load the image collection
//var Daily = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY");
var Daily = ee.ImageCollection("IDAHO_EPSCOR/TERRACLIMATE").select('tmmx');
// make monthly summed 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 summedImage = yearCollection.filter(ee.Filter.calendarRange(m, m, 'month'))
.reduce(ee.Reducer.sum());
var date = ee.Date.fromYMD(y, m, 1).format("MM_dd_YYYY");
return summedImage.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());
// 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,
"PrecipitationHTL",
"PrecipitationHTL",
"PrecipitationHTL");