0

I am trying to convert my google earth engine image to a numpy array. I have used sampleRectangle but the scale seems to be set to 1 degree, way too large, even though the native resolution of the dataset is much smaller.

import numpy as np
import ee

ee.Authenticate()
ee.Initialize()

def get_mod16(date1,date2,geometry):
  mod16 = ee.ImageCollection('MODIS/006/MOD16A2')
  mod16_img = mod16.filterDate(date1,date2).select('ET').sum().multiply(10)
  return(mod16_img) 


def addGeometry(min_lon,max_lon,min_lat,max_lat):
  geom = ee.Geometry.Polygon(
      [[[min_lon, max_lat],
        [min_lon, min_lat],
        [max_lon, min_lat],
        [max_lon, max_lat]]])
  return(geom)

geom = addGeometry(-102, -97.76,37.0727,38.5997)

mod16 = get_mod16('2014-04-01','2014-10-01',geom)
array = mod16.sampleRectangle(region=geom)
nparray = np.array(array.get('ET').getInfo())

print(nparray.shape)

This returns an np array of size (2,5). I thought maybe it's because my region is too large. I modified the code so the region is quite small (0.01 degrees by 0.01 degrees). It then returns an array of size (1,1).

1 Answer 1

0

Carrying out reducers (like your sum()) on an Image Collection gets rid of the original projection and replaces it with the default projection, which has a scale of 1 degree.

So after doing that reduction you would have to reproject your image back to the original projection.

proj = ee.ImageCollection('MODIS/006/MOD16A2').first().projection()
origProj = mod16.reproject(proj)

Also see the documentation for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.