开发者社区> 问答> 正文

AI Earth代码运行后,影像无法显示在地图上,怎么回事?

AI Earth代码运行后,影像无法显示在地图上,怎么回事?导出影像是有的,打印影像信息也有就是不显示import aie
import calendar

认证和初始化AIE平台

aie.Authenticate()
aie.Initialize()

指定区域

shp = aie.FeatureCollection('user/f01c82488e9f83d4684c88f44f260a2e')
start_year = 2020
end_year = 2020
start_month = 7
end_month = 9
k = 5

创建地图实例

map = aie.Map(
center=shp.getCenter(),
height=800,
zoom=5
)

定义要使用的波段

bands = ['SR_B1', 'SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6','SR_B7', 'ST_B10']

数据可视化参数

vis_params = {
'bands': ['SR_B4', 'SR_B3', 'SR_B2'],
'min': 0.0,
'max': 0.3,
}

定义去云算法

def removeLandsatCloud(image):
cloudShadowBitMask = (1 << 4)
cloudsBitMask = (1 << 3)
qa = image.select('QA_PIXEL')
mask = qa.bitwiseAnd(aie.Image(cloudShadowBitMask)).eq(aie.Image(0)) \
.And(qa.bitwiseAnd(aie.Image(cloudsBitMask)).eq(aie.Image(0)))
return image.updateMask(mask)

def applyScaleFactors(image):
opticalBands = image.select('SR_B.').multiply(aie.Image(0.0000275)).add(aie.Image(-0.2))
thermalBands = image.select('ST_B.*').multiply(aie.Image(0.00341802)).add(aie.Image(149.0)).add(aie.Image(-273.5))
return image.addBands(opticalBands, None, True).addBands(thermalBands, None, True)

定义 filterByMonth 函数

def filterByMonth(dataset, shp, year, month):
_, max_day = calendar.monthrange(year, month)
start_date = f'{year:04d}-{month:02d}-01'
end_date = f'{year:04d}-{month:02d}-{max_day:02d}'

filtered = dataset.filterDate(start_date, end_date) \
                  .filterBounds(shp) \
                  .map(removeLandsatCloud).map(applyScaleFactors)

return filtered

定义 filterByMonthsRange 函数

def filterByMonthsRange(dataset, shp, year, start_month, end_month):
all_filtered_datasets = []
combined_dataset = aie.ImageCollection([])

for month in range(start_month, end_month + 1):
    monthly_filtered = filterByMonth(dataset, shp, year, month)
    all_filtered_datasets.append(monthly_filtered)

    # 逐月合并数据集
    combined_dataset = combined_dataset.merge(monthly_filtered)

return combined_dataset

for year in range(start_year, end_year + 1, k):
combined_dataset = aie.ImageCollection([])

# 根据年份选择数据集类型
dataset = aie.ImageCollection('LANDSAT_LC08_C02_T1_L2')

# 筛选特定月份的数据
combined_dataset = filterByMonthsRange(dataset, shp, year, start_month, end_month)

    # 打印数据集大小
print(f'Size of combined dataset for year {year}:', combined_dataset.size().getInfo())

# 计算中值影像
yearly_median_image = combined_dataset.select(bands).median().clipToCollection(shp)

print(f'Year: {year}')
print("Band count:", len(yearly_median_image.bandNames().getInfo()))
print("Band names:", yearly_median_image.bandNames().getInfo())


 # 如果中值影像有数据,继续可视化
if yearly_median_image:
    # 数据可视化
    map.addLayer(
        yearly_median_image,
        vis_params,
        f'Filled True Color {year}',
        bounds=yearly_median_image.getBounds()
    )
else:
    print(f'No image data for year {year}')

导出镶嵌影像

task = aie.Export.image.toAsset(yearly_median_image, 'he', 1000)

task.start()

最后,显示地图(如果AI Earth平台支持此类操作)

map

展开
收起
三分钟热度的鱼 2024-05-05 08:19:10 7 0
0 条回答
写回答
取消 提交回答
来源圈子
更多
收录在圈子:
基于达摩院在深度学习、计算机视觉等方向上的技术积累,结合阿里云强大算力支撑,提供遥感、气象等多源对地观测数据的云计算分析服务,用数据感知地球世界,让AI助力科学研究。
问答排行榜
最热
最新

相关电子书

更多
释放算力潜能,加速 AI 应用构建 立即下载
网易游戏机器学习云平台助力AI应用落地实践 立即下载
智算时代,基于 ACK 落地云原生AI 立即下载