繁体   English   中英

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

[英]METADATA of images from earth-engine by Python 2.7

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

我想在图片上找到METADATA。

为了说明,我使用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']

文档的这一部分解释了背景知识。

编辑:

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

例如,这是获得阴天像素百分比的方法:

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

0.664195

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM