【问题标题】:How to print reduced pixel value in google earth engine如何在谷歌地球引擎中打印减少的像素值
【发布时间】:2020-07-19 23:42:45
【问题描述】:

我尝试打印给定像素(点位置)的降水总和的值

 # pixel location
loc_point = ee.Geometry.Point([-0.627983, 52.074361])
# get precip
precip = ee.ImageCollection('NASA/GPM_L3/IMERG_MONTHLY_V06')\
.filterDate('2019-06-01', '2020-06-30')\
.filterBounds(loc_point)\
.select('precipitation')

# sum  
precip_sum = precip.reduce(ee.Reducer.sum())

# print sum precip value
precip_sum.get('precipitation_sum').getInfo()

【问题讨论】:

  • 行尾的反斜杠在几乎所有 Python 代码中都是不可读的邪恶。如果您试图避免使用 79 个字符 (pep8),请以可读的方式执行,例如:创建一个函数、使用多个变量、在 () 上换行。这样一来,由 blocks 和伪代码语法构成的语言将很容易阅读,因此您可以简单地用眼睛浏览代码并知道发生了什么,而不是在头脑中颠倒代码只是为了阅读它。使代码可读,它将使您将来的生活更轻松。

标签: python google-earth-engine


【解决方案1】:

reduce 操作会得到一个图像,其中包含整个图像集合的总和;在这种情况下,它会随着时间的推移而减少。为了获得单个像素的值,您还需要使用reduceRegion

reduceRegion 设计用于 2D 区域,因此您必须指定一些对于定义点不是绝对必要的东西:

precip_sum = (precip
  .reduce(ee.Reducer.sum())
  .reduceRegion(
    geometry=loc_point,
    reducer=ee.Reducer.first(),  # take one pixel (there will be only one)
    crs=precip.first().projection()  # doesn't matter but must pick one
  ))

注意:我还没有测试过这个确切的 Python;我从this Earth Engine JavaScript 转换了我测试过的语法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-18
    • 2019-01-05
    • 2019-08-25
    • 1970-01-01
    • 2023-04-03
    • 2020-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多