在AI Earth选择了这个研究区的两个波段进行spearmans相关性分析,为什么说我的函数'Image.reduce'异常:参数'reducer'不支持spearmansCorrelation类型?我看案例里也是两个波段啊。
import aie
aie.Authenticate()
aie.Initialize()
feature_collection = aie.FeatureCollection('China_Province') \
.filter(aie.Filter.eq('province', '四川省')).geometry()
image_collection = aie.ImageCollection('MODIS_MOD17A2H_006') \
.filterBounds(feature_collection) \
.filterDate('2018-10-01', '2020-10-31') \
.mean() \
.clip(feature_collection)
corrleation = image_collection.select(['Gpp', 'PsnNet']) \
.reduce(aie.Reducer.spearmansCorrelation())
print(reduce_image.getInfo())
map = aie.Map(
center=reduce_image.getCenter(),
height=800,
zoom=7
)
vis_params = {
'bands': ['mean'],
'min': 8000,
'max': 13000,
}
map.addLayer(
reduce_image,
vis_params,
'reduce image',
bounds=reduce_image.getBounds()
)
map
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
根据您提供的代码,问题出在这一行:
reduce_image = image_collection.reduce(aie.Reducer.spearmansCorrelation())
aie.Reducer.spearmansCorrelation()
是一个用于计算 Spearman 相关系数的函数,它需要两个波段作为输入。但在您的代码中,您试图将这个函数应用于整个图像集合(image_collection
),这是不正确的。
正确的做法是先选择两个波段,然后使用 aie.Reducer.spearmansCorrelation()
函数计算它们之间的相关性。以下是修改后的代码:
import aie
aie.Authenticate()
aie.Initialize()
# 指定需要检索的区域
feature_collection = aie.FeatureCollection('China_Province') \n .filter(aie.Filter.eq('province', '四川省')).geometry()
# 指定检索数据集,可设置检索的空间和时间范围,以及属性过滤条件(如云量过滤等)
image_collection = aie.ImageCollection('MODIS_MOD17A2H_006') \n .filterBounds(feature_collection) \n .filterDate('2018-10-01', '2020-10-31') \n .mean() \n .clip(feature_collection)
# 选择两个波段
selected_bands = image_collection.select(['Gpp', 'PsnNet'])
# 计算两个波段之间的 Spearman 相关系数
corrleation = selected_bands.reduce(aie.Reducer.spearmansCorrelation())
print(corrleation.getInfo())
# 结果预览
map = aie.Map(
center=corrleation.getCenter(),
height=800,
zoom=7
)
vis_params = {
'bands': ['mean'],
'min': 8000,
'max': 13000,
}
map.addLayer(
corrleation,
vis_params,
'reduce image',
bounds=corrleation.getBounds()
)
map
这段代码首先选择了两个波段('Gpp' 和 'PsnNet'),然后使用 aie.Reducer.spearmansCorrelation()
函数计算它们之间的相关性。最后,将结果添加到地图上进行预览。
aie.Reducer.spearmansCorrelation只能应用于ImageCollection.reduce、Image.reduceRegion|reduceRegions或FeatureCollection.reduceColumns。可以具体参考文档:https://engine-aiearth.aliyun.com/docs/page/api?d=aeb7d9#heading-0
你上面的程序,image_collection调用过mean()函数,已经不是ImageCollection,而是Image,所以不能使用该相关性分析(你可以认为在同一位置,需要不同时相影像,所以得是ImageCollection) 此回答整理自钉群“AI Earth地球科学云平台交流群”