no classification
no tag
no datas
posted on 2023-11-12 14:30 read(875) comment(0) like(20) collect(2)
I am having problems importing data from Google Earth Engine to a local array using Python API.
A simplified version of my code:
import ee
ee.Initialize()
#Load a collection
TERRA = ee.ImageCollection("MODIS/006/MOD09A1").select(['sur_refl_b02', 'sur_refl_b07',"StateQA"])
TERRA = TERRA.filterDate('2003-01-01', '2019-12-31')
#Extract an image
TERRA_list = TERRA.toList(TERRA.size())
Terra_img = ee.Image(TERRA_list.get(1))
#Load as array
Terra_img = Terra.get('sur_refl_b02')
np_arr_b2 = np.array(Terra_img.getInfo())
But np_arr_b2
seems to be empty
Does anybody know what am I doing wrong?
Thanks!
You are not far from the goal, at least to a certain extent. There's a limit to how many pixels can be transferred over such a request, namely 262144. Your image, when taken over the whole globe (like you are doing), has 3732480000 - over 10000x too many. Still, you can sample a small area and put in the numpy:
import ee
import numpy as np
import matplotlib.pyplot as plt
ee.Initialize()
#Load a collection
TERRA = ee.ImageCollection("MODIS/006/MOD09A1").select(['sur_refl_b02', 'sur_refl_b07',"StateQA"])
TERRA = TERRA.filterDate('2003-01-01', '2019-12-31')
#Extract an image
TERRA_list = TERRA.toList(TERRA.size())
Terra_img = ee.Image(TERRA_list.get(1))
img = Terra_img.select('sur_refl_b02')
sample = img.sampleRectangle()
numpy_array = np.array(sample.get('sur_refl_b02').getInfo())
It's an area over Wroclaw, Poland, and looks like this when passed to matplotlib via imshow
:
What if you really need the whole image? That's where Export.image.toDrive
comes into play. Here's how you'd download the image to the Google Drive:
bbox = img.getInfo()['properties']['system:footprint']['coordinates']
task = ee.batch.Export.image.toDrive(img,
scale=10000,
description='MOD09A1',
fileFormat='GeoTIFF',
region=bbox)
task.start()
After the task is completed (which you can monitor also from Python), you can download your image from Drive and access it like any other GeoTIFF (see this GIS Stack Exchange post).
Author:qs
link:http://www.pythonblackhole.com/blog/article/245160/2ed4b1ca8f4b71fc8c27/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!