我试图将这段代码从EarthEngine (JavaScript)重写到RGEE:
function collection_index(image) {
function setNdviMinMax(img) {
var minMax = img
.select('NDVI')
.reduceRegion({
reducer: ee.Reducer.minMax(),
scale: 20,
maxPixels: 1e13
});
return img.set({
'NDVI_min': minMax.get('NDVI_min'),
'NDVI_max': minMax.get('NDVI_max'),
});
}
var ndvi_param = image.normalizedDifference(['B8', 'B4']);
ndvi_param = ndvi_param.rename('NDVI');
var SWIR_param = image.select('B12').rename('SWIR').divide(10000);
var STR_param = SWIR_param.expression(
'((1-SWIR)**2)/(2*SWIR)',{
'SWIR' : SWIR.select('SWIR'),
}).rename('STR')
ndvi_param = setNdviMinMax(ndvi_param)
ndvi_param = ndvi_param.updateMask(agrico)
return ndvi_param.addBands(STR_param)
}
var coll = S2.map(collection_index)
print(coll)我就这样做了:
collection_index <- function(image){
setNdviMinMax <- function(img){
minMax <- img$select('NDVI')$
reduceRegion(list(reducer= ee$Reducer$minMax(),
scale= 20,
maxPixels = 1e+09)
)
return(img$set(
list(
'NDVI_min'= minMax$get('NDVI_min'),
'NDVI_max'= minMax$get('NDVI_max')
)
)
)
}
ndvi_param <- image$normalizedDifference(list("B8", "B3"))
ndvi_param <- ndvi_param$rename('NDVI')
SWIR_param <- image$select('B12')$rename('SWIR')$divide(10000)
STR_param <- SWIR_param$expression('((1-SWIR)**2)/(2*SWIR)', list('SWIR' = SWIR$select('SWIR')))$rename('STR')
ndvi_param <- setNdviMinMax(ndvi_param)
ndvi_param <- ndvi_param$updateMask(agrico)
return(ndvi_param$addBands(STR_param) )
}
coll <- S2$map(collection_index)
ee_print(coll)但是,我有以下错误:
py_call_impl中的错误(可调用的,点$args,点$关键字):RuntimeError:计算错误: ee.ee_exception.EEException: ee.Reducer()的无效参数:({‘还原者’:0x7fd1e3548220>上的
有人能帮我解决这个错误吗?
非常感谢
https://code.earthengine.google.com/42db584622de1309c60faf4cb5f88573
发布于 2022-08-15 17:11:13
我不知道R,所以这完全是基于看别人的例子,但我确信错误在这里:
reduceRegion(list(reducer= ee$Reducer$minMax(),
scale= 20,
maxPixels = 1e+09)
)reduceRegion使用的不是字典,而是命名参数。所以这应该是
reduceRegion(
reducer = ee$Reducer$minMax(),
scale = 20,
maxPixels = 1e+09
)https://stackoverflow.com/questions/73357157
复制相似问题