TransWikia.com

Exporting district level precipitation data for series of months using Google Earth Engine Python API

Geographic Information Systems Asked by Smallex on March 31, 2021

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:UsersLeslieOneDriveRaw GIS DataAdmin_District_PESS_2014Original dbf FileSOM_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.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP