I'm trying to extract a monthly precipitation value from the PRISM climate dataset for each month of 2018 through 2021 (48 months total) for each US county in my shapefile (952 counties total) in Google Earth Engine. My goal is to export this as a table to then use for analyses in R. I believe I've completed the first step in the code below, but I'm unable to export the data to my Google Drive. Every time I try to export the data, the export runs for >4 hours without completion. I've tried removing the geometry portion and I've tried running this on only 2-4 months' worth of data, but my export never finishes.
Is this due to the size of the data/computer and network strength, or is there something in my code that is causing this export to continue for hours without successfully exporting?
I'm new to GEE and coding in general.
//Shapefile: 15 states, all counties
var countyList = ee.FeatureCollection(table);
print(countyList.size(), 'counties');
//Map.addLayer(countyList,{}, 'counties');
//Map.setCenter(-84.106, 42.424, 4.5);
//PRISM climate dataset
var precip = ee.ImageCollection('OREGONSTATE/PRISM/AN81m')
.select('ppt')
.filterBounds (countyList)
.filterDate('2018-01', '2022-01');
// Specify the date range required
var startDate = ee.Date('2018-01');
var endDate = ee.Date('2022-01');
print('Observations begin on: ', startDate.format('YYYY-MM'),
'and end on: ', endDate.format('YYYY-MM'));
// Calculate the number of months to process
var nMonths = ee.Number(endDate.difference(startDate, 'month')).round();
print('Number of months to process: ', nMonths);
//Calculate monthly precipitation for each county
var monthprecipcounty = ee.FeatureCollection(ee.List.sequence (0, nMonths.subtract(1))
.map(function(monthoffset) {
var month = startDate.advance(ee.Number(monthoffset), 'months')
var monthlymean = precip
.filterDate(month, month.advance (1, 'months'))
.mean()
return countyList.map(function (county) {
var mean = monthlymean.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: county.geometry(),
scale: 4638.3
})
return county
.set(mean)
.set('month', month.format('yyyy-MM'))
})
})
).flatten();
//Remove geometry from data for export: I tried this but it didn't make export any simpler
//var featureCollection = monthprecipcounty.map(function(feat){
// var nullfeat = ee.Feature(null)
// return nullfeat.copyProperties(feat)
//})
//Export county-level precip data to Google Drive
Export.table.toDrive({
collection: monthprecipcounty,
description: 'precip',
folder: 'this',
fileNamePrefix: 'precip',
fileFormat: 'CSV',
});
https://code.earthengine.google.com/c2ae03b6ec2d7bfe5151aafac3a85a54