monthly rainfall

Calculate monthly rainfall

Step 1: import the chirps data

Step 2: Set the date variables

// set start and end year
var startyear = ??;
var endyear = ??;

// 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(??, ??);

Step 3: Set the geographic location

// Specify Country names
var country_names = ['Sri Lanka'];

// Get the country boundaries
var countries = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw');

// Filter for country
var SriLanka = countries.filter(ee.Filter.inList('Country', country_names));

// Get the geometry
var SriLanka = SriLanka.geometry();

Step 4:Calculate monthly precipitation

var monthlyPrecip =  ee.ImageCollection.fromImages( (y) {
    return {
      var w = chirps.filter(ee.Filter.calendarRange(y, y, 'year'))
                    .filter(ee.Filter.calendarRange(m, m, 'month'))
      return w.set('year', y)
              .set('month', m)
              .set('system:time_start', ee.Date.fromYMD(y, m, 1));


Step 5: Calculate monthly precipitation

var meanMonthlyP =  ee.ImageCollection.fromImages( (m) {
    var w = monthlyPrecip.filter(ee.Filter.eq('month', m)).??();
    return w.set('month', m)
            .set('system:time_start',ee.Date.fromYMD(1, m, 1));

Step 6: Create and plot the chart

var title = {
  title: 'Monthly precipitation',
  hAxis: {title: 'Time'},
  vAxis: {title: 'Precipitation (mm)'},

var chartMonthly = ui.Chart.image.seriesByRegion({
  imageCollection: meanMonthlyP,
  regions: SriLanka,
  reducer: ee.Reducer.mean(),
  band: 'precipitation',
  scale: 2500,
  xProperty: 'system:time_start',
  seriesProperty: 'SITE'



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s