来自Python 2.7的地球引擎图像的METADATA

时间:2019-05-20 08:17:51

标签: python python-2.7 sentinel google-earth-engine

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

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

为说明起见,我使用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"
})

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

1 个答案:

答案 0 :(得分:0)

这是由于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