我想从COPERNICUS/S2_SR
集合中获取"B2","B3","B4","B8","NDVI","SAVI" and "TVI"
平均数据,按日期/平铺。我喜欢提取这些波段和植被指数意味着在我的ROI和我创建一个s2_clean
功能波段选择和指数创建,但不工作。我试着去做:
# Packages
library(tidyverse)
library(rgee)
library(sf)
ee_Initialize(drive=TRUE)
# Function for remove cloud and shadows ------------------------------------------
getQABits <- function(image, qa) {
# Convert decimal (character) to decimal (little endian)
qa <- sum(2^(which(rev(unlist(strsplit(as.character(qa), "")) == 1))-1))
# Return a single band image of the extracted QA bits, giving the qa value.
image$bitwiseAnd(qa)$lt(1)
}
# Selection of bands and vegetation indices ---------------------------------------
s2_clean <- function(img) {
# Select NDVI
img_band_selected <- img$select("B[2-4|8]")
# quality band
ndvi_qa <- img$select("QA60")
# Select pixels to mask
quality_mask <- getQABits(ndvi_qa, "110000000000")
# Mask pixels with value zero.
img_band_selected$updateMask(quality_mask)
# Lists of bands and vegetation indices
B2 <- img$select("B2")
B3 <- img$select("B3")
B4 <- img$select("B4")
B8 <- img$select("B8")
NDVI <- img_band_selected$select("B8")$subtract(img_band_selected$select("B4"))$divide(img_band_selected$select("B8")$add(img_band_selected$select("B4")))
SAVI <- 1.5*img_band_selected$select("B8")$subtract(img_band_selected$select("B4"))$divide(img_band_selected$select("B8")$subtract(img_band_selected$select("B4"))$add(0.5))
TVI <- 0.5$multiply(120$multiply(img_band_selected$select("B8")$subtract(img_band_selected$select("B4")))-(200*(img_band_selected$select("B3")$subtract(img_band_selected$select("B2")))))
select<- c(B2,B3,B4,B8,NDVI,SAVI,TVI)
return(selected)
}
# Define a Region of interest
roi <-ee$Geometry$Point(-52.19032,-30.25413)$buffer(500)
# Sentinel-2 MSI dataset into the Earth Engine’s public data archive ------------
s2 <- ee$ImageCollection("COPERNICUS/S2_SR")
# Select S2 images ---------------------------------------------------------------
s2_roi <- s2$
filterBounds(roi)$
filter(ee$Filter$lte("CLOUDY_PIXEL_PERCENTAGE", 1))$
filter(ee$Filter$date(as.character(as.Date("2019-12-04")), as.character(as.Date("2020-05-03"))))$
map(s2_clean)
s2_roi_add_area <- s2_roi$map(
function(img) {
img$set("area", img$clip(roi)$geometry()$area())
}
)
#Extract average NDVI values
ee_mean<- ee_extract(
x = s2_roi_add_area,
y = roi,
scale = 10,
fun = ee$Reducer$mean(),
via = "drive"
)
ee_mean
但我总是有输出:
Error in py_call_impl(callable, dots$args, dots$keywords) : RuntimeError: Evaluation error: non-numeric argument to binary operator.
拜托,有什么能帮忙的吗?
1条答案
按热度按时间mnemlml81#
我认为问题在于,在s2_clean()函数中,你对数字使用了$运算符,正确的等式应该是: