I'm new to GEE and am trying to get the average precipitation over a time period 1981-2019 for geometries along a transect. Here is my code:
def yearlyRainfall(year):
startDate = ee.Date.fromYMD(year, 1, 1)
endDate = startDate.advance(1, 'year')
filtered = chirps.filter(ee.Filter.date(startDate, endDate))
total = filtered.reduce(ee.Reducer.sum())
stats = total.reduceRegion(
reducer = ee.Reducer.mean(),
geometry = circles_collection,
scale = 5000,
)
f = ee.Feature(None,{
'year': year,
'precipitation': stats.get('precipitation_sum')
})
return f
years = ee.List.sequence(1981, 2019)
rainfallYears = ee.FeatureCollection(years.map(yearlyRainfall))
rainfalldf = geemap.ee_to_pandas(rainfallYears)
print(rainfalldf["precipitation"].mean())
This code can find the mean precipitation for all the geometries in circles_collection. However, I want to make a separate feature collection for each geometry within the feature collection so I can get the precipitation data for the individual geometries, rather than averaging all of them. Any help is appreciated.
Tried: adding "geo" parameter to yearlyRainfall(), produces error when trying to map over a function that takes in an alternate parameter
Use
reduceRegions
instead. Also, create an image with bands for all years instead of mapping over the years so you only do the reduce call once.