使用 R 处理 google 地球引擎数据

Using R to process google earth engine data

我想从 NASA 下载给定纬度的每日 tmax (https://developers.google.com/earth-engine/datasets/catalog/NASA_NEX-DCP30_ENSEMBLE_STATS) 使用以下教程 https://jesjehle.github.io/earthEngineGrabR/index.html

library(devtools)
install_github('JesJehle/earthEngineGrabR')
library(earthEngineGrabR)
ee_grab_install() # had to install Anaconda before doing this step.

test_data <- ee_grab(data = ee_data_collection(datasetID = "NASA/NEX-DCP30_ENSEMBLE_STATS",
                                               timeStart = "1980-01-01",
                                               timeEnd = '1980-01-02',
                                               bandSelection = 'tasmax'), 
    targetArea = system.file("data/territories.shp", package = "earthEngineGrabR")
    )

Error: With the given product argument no valid data could be requested.
In addition: Warning message:
Error on Earth Engine servers for data product: NASA-NEX-DCP30_ENSEMBLE_STATS_s-mean_t-mean_1980-01-01to2005-12-31
Error in py_call_impl(callable, dots$args, dots$keywords): EEException: Collection.first: Error in map(ID=historical_195001):
Image.select: Pattern 'tasmax' did not match any bands.

我想知道如何指定带宽,这样我才能得到这个错误,而不是使用 shapefile 作为目标区域,我是否下载单个经纬度 9.55、78.59 的 tmax 数据?

您可以使用 rgee 来完成此操作。目前,rgee 有一个名为 rgee::ee_extract 的函数,其工作方式类似于 raster::extract().

library(rgee)
library(sf)

# 1. Load a geometry
y <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) %>%
  st_transform(4326)
## Move that geometry from local to earth engine
ee_y <- sf_as_ee(y)

# 2. Load your ImageCollection
x <- ee$ImageCollection("NASA/NEX-DCP30_ENSEMBLE_STATS")$
  filterDate("1980-01-01","1980-01-02")$
  map(function(img) img$select("tasmax_mean"))
## calculate the nominal scale
scale <- x$first()$projection()$nominalScale()$getInfo() 

# 3. Extract values
tasmax_mean_data <- ee_extract(x = x,
                               y =  y, 
                               fun = ee$Reducer$mean(),
                               scale = scale, 
                               id = "FIPS")

# 4. Merge results with the sf object
ee_nc_tasmax <- merge(y, tasmax_mean_data, by = "FIPS")
plot(ee_nc_rain['historical_198001'])