1

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 JS 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 expection as follows: ee.ee_exception.EEException Projection: Argument 'crs': Invalid type. Expected: String. Actual: Type>.

2

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.

  • Thank you so much for solving my problem Alami. I'm new in python and i thought the proj was a dict type so i should also use a dict to assign the arguments. Do you know how to check the format of parameters in python? – myzhenghr Mar 26 at 1:45
  • Arguments are always defined the exact same way (argument=value). On another note, dictionaries are also defined without quotes {key: value}. I would highly recommend you check out this website for future references. – Mouad Alami Mar 26 at 6:21
  • OK,i will carefully read it. Thank you for your kindness reply and advice. – myzhenghr Mar 27 at 1:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.