无法从Google Earth Engine导出VIIRS-DNB年度合成影像问题
问题:导出乌克兰VIIRS年度合成影像时出现「Image.clipToBoundsAndScale: The image must have at least one band.」错误
我尝试获取2012-2021年乌克兰区域的VIIRS-DNB年度合成影像并导出,已编写代码生成年度合成影像集:
# define our start and end years start = 2012 end = 2021 years = ee.List.sequence(start, end) colID = "NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG" def viirs_annual_median_reduce(year): return ee.ImageCollection(colID).filter( ee.Filter.calendarRange(year,year,"year")).select("avg_rad").median().set('year',year) # map function to each year in our list yearComps = ee.ImageCollection.fromImages(years.map(viirs_annual_median_reduce)) # get boundaries for Ukraine aoi_UA = ee.FeatureCollection('FAO/GAUL_SIMPLIFIED_500m/2015/level0').filter(ee.Filter.eq('ADM0_CODE', 254)) # clipping image to only include nightlight data for Ukraine viirs_UA = yearComps.map(lambda x: x.clip(aoi_UA))
因不清楚如何导出影像集,选择逐个导出影像:
img1 = viirs_UA.filterMetadata("year","equals",2012).first() task = ee.batch.Export.image.toDrive(image=img1, fileFormat='GeoTIFF', description='Ukraine_VIIRS_2012', scale=30, folder='tmp', maxPixels=1e9) task.start()
运行task.status()时出现错误:'error_message': 'Image.clipToBoundsAndScale: The image must have at least one band.',请问哪里操作有误?
错误原因
核心问题是你指定的NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG数据集起始时间为2014年4月,2012、2013年没有可用的月度影像数据。对空影像集执行.median()操作会生成一个没有任何波段的空影像,后续裁剪、导出自然会触发「无波段」错误。
修复方案
1. 调整年份范围至数据集可用区间
直接修改起始年份为2014,确保每个年度都有可用影像:
start = 2014 # 替换原2012,匹配数据集起始时间 end = 2021
2. (可选)增加空影像判断,避免无效合成
在年度合成函数中加入集合非空判断,防止生成无波段影像,同时标记无效年份:
def viirs_annual_median_reduce(year): annual_col = ee.ImageCollection(colID).filter(ee.Filter.calendarRange(year, year, "year")) # 仅当集合非空时计算中位数,否则返回带标记的空影像 return ee.Algorithms.If( annual_col.size().gt(0), annual_col.select("avg_rad").median().set('year', year), ee.Image().set('year', year).set('empty', True) )
3. 导出前过滤无效影像
如果保留了2012-2013年的年份范围,导出前先过滤掉标记为empty的无效影像:
# 过滤掉空影像,只保留有效合成结果 viirs_UA_valid = viirs_UA.filter(ee.Filter.notNull(['empty']))
之后再执行逐个导出操作,就不会触发无波段错误了。
内容的提问来源于stack exchange,提问作者Val_hat
相关产品推荐
相关产品推荐

