Annual rainfall

Calculate annual rainfall from chirps

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 = ['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));<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>

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: SriLanka,
  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(SriLanka);

Step 7: Calculate the mean of the period

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

Step 8: show the map

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

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

See an example here.

One comment

  1. Hi thank you for the information. I am trying to display ‘Evap_tavg’ using ‘FLDAS’ data but i cannot seem to display only the ‘Evap_tavg’. Please let me know where i go wrong. this is the code. Especially the last 9 lines of code.

    // set start and end year
    var startyear = 1987;
    var endyear = 2016;

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

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

    var title = {
    title: ‘Annual Evapotranspiration’,
    hAxis: {title: ‘Time’},
    vAxis: {title: ‘Evapotranspiration (kg m-2 s-1)’},
    };

    var chart = ui.Chart.image.seriesByRegion({
    imageCollection: annualET,
    regions: Africa,
    reducer: ee.Reducer.mean(),
    band: ‘Evap_tavg’,
    scale: 2500,
    xProperty: ‘system:time_start’,
    seriesProperty: ‘SITE’
    }).setOptions(title)
    .setChartType(‘ColumnChart’);

    print(chart);

    var ETlayer = annualET.select(‘Evap_tavg’);
    var annualMean = ETlayer.mean().clip(Africa);

    var ETViz = {
    min: 1000,
    max: 5000,
    palette: ‘000000, 0000FF, FDFF92, FF2700, FF00E7’
    };

    Map.centerObject(Africa, 5);
    Map.addLayer(annualMean, ETViz, ‘mean yearly ET’);

Leave a Reply to fredlink8 Cancel reply