Annual rainfall

Calculate yearly amount of rainfall in your country

Step 1: import the chirps data

Step 2: Set the date variables

// set start and end year
var startyear = 2000;
var endyear = 2014;

// 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);

Step 3: Set the geographic location

// Specify Country names
var country_names = ['Indonesia'];

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

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

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

Step 4: Calculate the yearly precipitation

var annualPrecip = ee.ImageCollection.fromImages(
  years.map(function (year) {
    var annual = chirps
        .filter(ee.Filter.calendarRange(year, year, 'year'))
        .sum();
    return annual
        .set('year', year)
        .set('system:time_start', ee.Date.fromYMD(year, 1, 1));
}));

Step 5: Make a chart of the data

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

var chart = ui.Chart.image.seriesByRegion({
  imageCollection: annualPrecip,
  regions: Indonesia,
  reducer: ee.Reducer.mean(),
  band: 'precipitation',
  scale: 2500,
  xProperty: 'system:time_start',
  seriesProperty: 'SITE'
}).setOptions(title)
  .setChartType('ColumnChart');

Step 6: Calculate the mean of the period

var annualMean = annualPrecip.mean().clip(Indonesia);

Step 7: Calculate the mean of the period

var annualMean = annualPrecip.mean().clip(Indonesia);

Step 8: show the map

var pViz = {
  min: 2000,
  max: 5500,
  palette: '000000, 0000FF, FDFF92, FF2700, FF00E7'
};

Map.centerObject(Indonesia, 5);
Map.addLayer(annualMean, pViz, 'mean yearly P');

See an example here.

Leave a Reply