Python 2.7 来自 earth-engine 的图像元数据

METADATA of images from earth-engine by 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 函数时,它只会打印 json 对象,该对象将被发送到 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']

section of the documentation解释了背景。

编辑:

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

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

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

0.664195