Google Earth Engine Resampling – Resampling Image to Higher Resolution Using Python API

google-earth-enginegoogle-earth-engine-python-api

I try to use resample and reproject function in GEE to downscale the MODIS 250 products into 240m in order to correspond the 8*8 Landsat 30m pixels for furture purpose.

I used a Landsat image for example. Change image resolution in GEE is implemented by ee.image.reproject() function. Followed by the resolution given by Kersten and Tyler Erickson, I re-wrote the JavaScript code into Python as follows:

import ee
ee.Initialize()

Reference a Landsat scene.

image_30m = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20170614')

get the image projection by querying the projection of band2

band2 = image_30m.select('B2')
proj = band2.projection().getInfo()
crs = proj['crs']

resample and reproject the image to 10m

image_10m = image_30m.resample('bilinear').reproject({
'crs': crs,
'scale': 10.0})

image_10m_band2 = image_10m.select('B2')

get the projected image's projection and print

newproj = image_10m_band2.projection().getInfo()

print('New projection', newproj)

#I also tried another version

transform_new = [
10.0,
proj['transform'][1],
proj['transform'][2],
proj['transform'][3],
-10.0,
proj['transform'][5]
]

projection_new = {
'crs': crs,
'transform': transform_new,
}

image_10m = image_30m.resample('bilinear').reproject(projection_new)

When I check the reprojected image's projection, I expected to obtain the projection in 10m, but only I got is a exception as follows:

ee.ee_exception.EEException Projection: Argument 'crs': Invalid type.
Expected: String. Actual: Type>.

Best Answer

That's because the process of argument assignment in python is different than that of JS.

This part ({'crs': crs,'scale': 10.0}) needs to be replaced with its python equivalent.

Your code should look like:

image_10m = image_30m.resample('bilinear').reproject(crs=crs, scale=10)

Please note that arguments are never to be put in quotes in python.