The code below extracts average rainfall for each US county for one given day and send the table result to drive. Now, how can I use iterate function to extract a time series for one year for example?
// load precip data (mm, daily )
var precipCollection = ee.ImageCollection('OREGONSTATE/PRISM/AN81d')
.select('ppt') // select precip band only
.filterDate('2017-01-01'); // e.g. one day
print(precipCollection, 'precipCollection');
//reduce the image collection
var dailyPrecip = precipCollection.reduce(ee.Reducer.sum());
print(dailyPrecip);
// visualize annual precipitation
var precipPal = ['white','blue','red','pink'] // store palette as variable
Map.addLayer(dailyPrecip, {min: 1, max: 100, palette: precipPal}, 'precip');
////////////////////////////////////
// load regions: counties from a public fusion table, removing non-conus states
// by using a custom filter
var nonCONUS = [2,15,60,66,69,72,78] // state FIPS codes that we don't want
var counties = ee.FeatureCollection('ft:1ZMnPbFshUI3qbk9XE0H7t1N5CjsEGyl8lZfWfVn4')
.filter(ee.Filter.inList('STATEFP',nonCONUS).not());
print(counties, 'counties');
// visualize
Map.addLayer(counties,{},'counties');
// get mean precipitation values by county polygon
var countyPrecip = dailyPrecip.reduceRegions({
collection: counties,
reducer: ee.Reducer.mean(),
scale: 4000 // the resolution of the prism dataset
});
print(countyPrecip);
// select features
var out = countyPrecip.select(['.*']);
// add a new column for date
out = out.map(function(feature){
return feature.set('date','2017-01-01');
});
// Table to Drive Export Example
Export.table.toDrive({
collection: out,
description: 'precip_by_county',
folder: 'GEE',
fileFormat: 'CSV'
});