I am still new to the Google Earth Engine and try to calculate the daily precipitation based on the CHIRPS. I have created a code to calculate monthly precipitation.
Could you advise me on how I change this code to daily precipitation?
var chirps = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY"),
geometry = /* color: #d63000 */ee.Geometry.MultiPoint();
// set start and end year
var startyear = 2018;
var endyear = 2020;
// make a date object
var startdate = ee.Date.fromYMD(startyear, 1, 1);
var enddate = ee.Date.fromYMD(endyear + 1, 1, 1);
// make a list with years
var years = ee.List.sequence(startyear, endyear);
// make a list with months
var months = ee.List.sequence(1, 12);
// Specify Country names
var worldcountries = ee.FeatureCollection('FAO/GAUL/2015/level2');
var filterCountry = ee.Filter.eq('ADM2_NAME', 'Kurgantepa district');
var country = worldcountries.filter(filterCountry);
Map.addLayer(country);
Map.centerObject(country, 6);
// Get the geometry
var country = country.geometry();
var monthlyPrecip = ee.ImageCollection.fromImages(
years.map(function (y) {
return months.map(function(m) {
var w = chirps.filter(ee.Filter.calendarRange(y, y, 'year'))
.filter(ee.Filter.calendarRange(m, m, 'month'))
.sum();
return w.set('year', y)
.set('month', m)
.set('system:time_start', ee.Date.fromYMD(y, m, 1));
});
}).flatten()
);
var meanMonthlyP = ee.ImageCollection.fromImages(
months.map(function (m) {
var w = monthlyPrecip.filter(ee.Filter.eq('month', m)).mean();
return w.set('month', m)
.set('system:time_start',ee.Date.fromYMD(2018, m, 1));
}).flatten()
);
var title = {
title: 'Monthly precipitation',
hAxis: {title: 'Time'},
vAxis: {title: 'Precipitation (mm)'},
};
var chartMonthly = ui.Chart.image.seriesByRegion({
imageCollection: meanMonthlyP,
regions: country,
reducer: ee.Reducer.mean(),
band: 'precipitation',
scale: 5000,
xProperty: 'system:time_start',
seriesProperty: 'SITE'
}).setOptions(title)
.setChartType('ColumnChart');
print(chartMonthly);