Point sampling with Google Earth Engine

Ground-truthing has never been so easy as with the GEE.

In this excercise we are going to validate the CHIRPS rainfall product with rainfall stations in the field.

Step 1: Import the Chirps image collection into the GEE.

Step 2: Import the fusion table with field measurement location.

var Rainfallstations = ee.FeatureCollection('ft:1vnNFgZt4avuVXjYm2gYsqr-25hzVefHUq3TCwUCu','geometry');

Step 3: Setup the time range for the dataseries.

// Define time range
var startyear = 2000;
var endyear = 2005;

// Set date in ee date format
var startdate = ee.Date.fromYMD(startyear,1,1);
var enddate = ee.Date.fromYMD(endyear,12,31)

Step 4: Create a list with years and months.

// create list for years
var years = ee.List.sequence(startyear,endyear);

// make a list with months
var months = ee.List.sequence(1,12);

Step 5: Filter for data and location.

// Filter chirps
var Pchirps = chirps.filterDate(startdate, enddate)
  // Sort chronologically in descending order.
  .sort('system:time_start', false)
  .filterBounds(Rainfallstations)
  .select("precipitation");

Step 6: Calculate the monthly rainfall with the function below.

// calculate the P for each month
var MonthlyChirps =  ee.ImageCollection.fromImages(
  years.map(function (y) {
  return months.map(function(m){
    var w = Pchirps.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))
             .set('date', ee.Date.fromYMD(y,m,1))
});
}).flatten());

Step 7: Add the sampling points to the map

// add items to the map
Map.centerObject(Rainfallstations,8);
Map.addLayer(Rainfallstations,false,"rainfall stations");

Step 8: Create a chart that samples all points for the whole image collection

// Predefine the chart titles.
var title = {
  title: 'Precipitation',
  hAxis: {title: 'Time'},
  vAxis: {title: 'P (mm)'},
};

// create a chart with a reducer
var chart = ui.Chart.image.seriesByRegion(
  MonthlyChirps, Rainfallstations, ee.Reducer.mean(), 'precipitation', 5000, 'system:time_start', 'station')
    .setOptions(title);

print(chart)

Step 9: Click the pop out icon in the right top corner.

graph

Step 10: Download the csv file.

saveascsv

Step 11: Calculate the mean and compare it with the measured data.

See an example here.

6 thoughts on “Point sampling with Google Earth Engine”

  1. Great post. Any idea how to turn the ImageCollection “MonthlyChirps” into a multiple band image for export, where each band represents the monthly aggregation?

    Like

      1. Thanks for a great post. Could you please calculate monthly TRMM rainfall data? TRMM has 3 hours data so the code does not work though.

        Like

  2. Do you know how to convert CHIRP-rainfall data to vector form? Specifically, I’m trying to get the average annual percipitation for each 0.5×0.5km square for one specified country. So instead of matching the data with rainfall stations as you have done here I’m looking for the data from all grid points.

    Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s