0

I am trying to export precipitation data for a range of months at the district level of Somalia using GEE's phython api. I'm using the following code

#import Somalia district shape file and convert to ee object

districts = geemap.shp_to_ee(r"C:\Users\Leslie\OneDrive\Raw GIS Data\Admin_District_PESS_2014\Original dbf File\SOM_Population_PESS_2014")

# import the RS products
chirps = ee.ImageCollection('UCSB-CHG/CHIRPS/PENTAD')
 
# Define time range
startyear = 2000
endyear = 2001
 
# create list for years
years = range(startyear,endyear);
 
# make a list with months
months = range(1,12);
 
# Set date in ee date format
startdate = ee.Date.fromYMD(startyear,1,1)
enddate = ee.Date.fromYMD(endyear+1,12,31)
 
# Filter chirps
Pchirps = chirps.filterDate(startdate, enddate).sort('system:time_start', False).select("precipitation")
 
# calculate the monthly mean
def calcMonthlyMean(imageCollection):
    mylist = ee.List([])
    for y in years:
        for m in months:
            w = imageCollection.filter(ee.Filter.calendarRange(y, y, 'year')).filter(ee.Filter.calendarRange(m, m, 'month')).sum();
            mylist = mylist.add(w.set('year', y).set('month', m).set('date', ee.Date.fromYMD(y,m,1)).set('system:time_start',ee.Date.fromYMD(y,m,1)))
    return ee.ImageCollection.fromImages(mylist)
 
# run the calcMonthlyMean function
monthlyChirps = ee.ImageCollection(calcMonthlyMean(Pchirps))

#function to apply reduceRegions over the districts feature collection 
def eeAlgo(image):
    reduced = image.reduceRegions(collection=districts, reducer=ee.Reducer.median(), scale= 5000)
    return image 

vals = monthlyChirps.map(algorithm=eeAlgo)

I am not sure if this is right especially since 'vals.getInfo()' does not indicate a property called district.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.