开发者社区> 问答> 正文

在AI Earth选择了这个研究区的两个波段进行spearmans相关性分析,为什么说我的函数异常?

在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)

reduce运算,指定一个Reducer

reduce_image = image_collection.reduce(aie.Reducer.spearmansCorrelation())

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

展开
收起
三分钟热度的鱼 2024-03-06 17:20:28 24 0
2 条回答
写回答
取消 提交回答
  • 面对过去,不要迷离;面对未来,不必彷徨;活在今天,你只要把自己完全展示给别人看。

    根据您提供的代码,问题出在这一行:

    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() 函数计算它们之间的相关性。最后,将结果添加到地图上进行预览。

    2024-03-08 20:42:15
    赞同 展开评论 打赏
  • 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地球科学云平台交流群”

    2024-03-06 18:30:47
    赞同 展开评论 打赏
来源圈子
更多
收录在圈子:
基于达摩院在深度学习、计算机视觉等方向上的技术积累,结合阿里云强大算力支撑,提供遥感、气象等多源对地观测数据的云计算分析服务,用数据感知地球世界,让AI助力科学研究。
问答排行榜
最热
最新

相关电子书

更多
Data+AI时代大数据平台应该如何建设 立即下载
大数据AI一体化的解读 立即下载
当搜索遇见AI 立即下载