# 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);
```

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.

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

See an example here.

1. Sean says:

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. Sean says:

Exactly like that. Thank you.

Like

1. NDM says:

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. sara davidsson says:

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

1. You can apply a reducer using e.g. the country administrative boundaries to get the mean annual precipitation.

Like

3. Raees Mukhtar says:

any idea how to get values at multiple points and export it into table with lat/lng and values in csv format

Like

4. Do a sampleregions and add a lon lat band to your image (
ee.Image.pixelLonLat())

Like

5. sm says:

I cannot try it out. The feature collection does not exist (publicly)

Like

6. Amit says:

I tried your script but it is showing me only one output in chart. any suggestions.

Like