来自 Python 2.7 的地球引擎图像的元数据



我正在尝试获取有关图片,云的状态,太阳角度以及我能获得的任何其他信息的信息。

我正在尝试获取图片上的元数据。

为了说明这一点,我使用CLOUD_COVER表示云的百分比,但我没有得到任何数值。

我的代码:

import ee
import ee.mapclient
ee.Initialize()
# Get a download URL for an image.
image1 = ee.Image('COPERNICUS/S2_SR/20190205T082129_20190205T082130_T36SYB');
#Get information about the bands as a list.
bandNames = image1.bandNames();
print ("Band names: " + str(bandNames)) #ee.List of band names
#Get projection information from band 1
b1proj = image1.select('B1').projection()
print('Band 1 projection: ' + str(b1proj))#ee.Projection object
#Get scale (in meters) information from band 1.
b1scale = image1.select('B1').projection().nominalScale()
print('Band 1 scale: ' + str(b1scale))#ee.Number
#Note that different bands can have different projections and scale.
b8scale = image1.select('B8').projection().nominalScale()
print('Band 8 scale: ' + str(b8scale))#ee.Number
#Get a list of all metadata properties.
properties = image1.propertyNames()
print('Metadata properties: ' + str(properties))#ee.List of metadata properties
#Get a specific metadata property.
cloudiness = image1.get('CLOUD_COVER')
print('CLOUD_COVER: ' + str(cloudiness))#ee.Number

下面是输出:

Band names: ee.List({
"type": "Invocation", 
"arguments": {
"image": {
"type": "Invocation", 
"arguments": {
"id": "COPERNICUS/S2_SR/20190205T082129_20190205T082130_T36SYB"
}, 
"functionName": "Image.load"
}
}, 
"functionName": "Image.bandNames"
})
Band 1 projection: ee.Projection({
"type": "Invocation", 
"arguments": {
"crs": {
"type": "Invocation", 
"arguments": {
"image": {
"type": "Invocation", 
"arguments": {
"bandSelectors": [
"B1"
], 
"input": {
"type": "Invocation", 
"arguments": {
"id": "COPERNICUS/S2_SR/20190205T082129_20190205T082130_T36SYB"
}, 
"functionName": "Image.load"
}
}, 
"functionName": "Image.select"
}
}, 
"functionName": "Image.projection"
}
}, 
"functionName": "Projection"
})
Band 1 scale: ee.Number({
"type": "Invocation", 
"arguments": {
"proj": {
"type": "Invocation", 
"arguments": {
"crs": {
"type": "Invocation", 
"arguments": {
"image": {
"type": "Invocation", 
"arguments": {
"bandSelectors": [
"B1"
], 
"input": {
"type": "Invocation", 
"arguments": {
"id": "COPERNICUS/S2_SR/20190205T082129_20190205T082130_T36SYB"
}, 
"functionName": "Image.load"
}
}, 
"functionName": "Image.select"
}
}, 
"functionName": "Image.projection"
}
}, 
"functionName": "Projection"
}
}, 
"functionName": "Projection.nominalScale"
})
Band 8 scale: ee.Number({
"type": "Invocation", 
"arguments": {
"proj": {
"type": "Invocation", 
"arguments": {
"crs": {
"type": "Invocation", 
"arguments": {
"image": {
"type": "Invocation", 
"arguments": {
"bandSelectors": [
"B8"
], 
"input": {
"type": "Invocation", 
"arguments": {
"id": "COPERNICUS/S2_SR/20190205T082129_20190205T082130_T36SYB"
}, 
"functionName": "Image.load"
}
}, 
"functionName": "Image.select"
}
}, 
"functionName": "Image.projection"
}
}, 
"functionName": "Projection"
}
}, 
"functionName": "Projection.nominalScale"
})
Metadata properties: ee.List({
"type": "Invocation", 
"arguments": {
"element": {
"type": "Invocation", 
"arguments": {
"id": "COPERNICUS/S2_SR/20190205T082129_20190205T082130_T36SYB"
}, 
"functionName": "Image.load"
}
}, 
"functionName": "Element.propertyNames"
})
CLOUD_COVER: ee.ComputedObject({
"type": "Invocation", 
"arguments": {
"property": "CLOUD_COVER", 
"object": {
"type": "Invocation", 
"arguments": {
"id": "COPERNICUS/S2_SR/20190205T082129_20190205T082130_T36SYB"
}, 
"functionName": "Image.load"
}
}, 
"functionName": "Element.get"
})

问题是输出没有信息。谁能解释为什么?

这是由于GEE的工作方式。处理步骤在本地构造为对象,然后仅在另一个函数需要时才由服务器进行评估。因此,当您使用 python 的print函数时,它只会打印jsonobect,该 obect 将被发送到 GEE 服务器进行评估。

您可以使用.getInfo()强制评估...但是,应谨慎使用,因为所有内容都被拉到客户端,这对于大型对象可能会有问题。

所以这有效:

import ee
ee.Initialize()
image1 = ee.Image('COPERNICUS/S2_SR/20190205T082129_20190205T082130_T36SYB')
bandNames = image1.bandNames()
print(bandNames.getInfo())
[u'B1', u'B2', u'B3', u'B4', u'B5', u'B6', u'B7', u'B8', u'B8A', u'B9', u'B11', u'B12', u'AOT', u'WVP', u'SCL', u'TCI_R', u'TCI_G', u'TCI_B', u'MSK_CLDPRB', u'MSK_SNWPRB', u'QA10',

u'QA20', u'QA60']

文档的这一部分介绍了背景。

编辑:

当然,如果使用get和相应的属性名称,则可以将其扩展到所有元数据属性。

例如,这是获取多云像素百分比的方式:

cloudiness = image1.get("CLOUDY_PIXEL_PERCENTAGE").getInfo()
print(cloudiness)

0.664195

最新更新