I'm trying to convert Earth Engine data to a local GeoTIFF manually, using more or less the method found here. One crucial step is converting the DEM raster values to a NumPy array. I've been trying to do so as follows:
ee.Initialize()
# define ROI
area = ee.Geometry.Rectangle(bounds)
# set image
img = ee.Image('USGS/SRTMGL1_003')
# get the lat lon and add the elevation data back in
latlng = ee.Image.pixelLonLat().addBands(img)
# reduce to list
latlng = latlng.reduceRegion(reducer=ee.Reducer.toList(), geometry=area, maxPixels=1e8, scale=20)
# put the values into lists
elev_values = np.array((ee.Array(latlng.get("elevation")).getInfo()))
lats = np.array((ee.Array(latlng.get("latitude")).getInfo()))
lngs = np.array((ee.Array(latlng.get("longitude")).getInfo()))
While I have had success converting unique latitude and longitude values to a NumPy array, I keep ending up with an empty array of elevation values. The current code throws the following error:
Traceback (most recent call last):
File "test_one.py", line 392, in <module>
gDem = GoogleDEM([40.01, -21.01, 40.02, -21.00])
File "test_one.py", line 41, in __init__
elev_values = np.array((ee.Array(latlng.get("elevation")).getInfo()))
File "C:\Users\lmonn\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ee\computedobject.py", line 95, in getInfo
return data.computeValue(self)
File "C:\Users\lmonn\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ee\data.py", line 490, in computeValue
return send_('/value', ({'json': obj.serialize(), 'json_format': 'v2'}))
File "C:\Users\lmonn\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ee\data.py", line 1186, in send_
raise ee_exception.EEException(json_content['error']['message'])
ee.ee_exception.EEException: Array: No numbers in 'values', must provide a type.
My guess would be that there is some nesting of objects taking place that I don't quite have a grasp on.
How can I fix this issue? Is there a simpler way to get a NumPy Array of the elevation values for a DEM on Earth Engine?