簡體   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