我正在尝试遍历一组 MODIS 数据以按周期计算平均值。由于 2000 年缺少 1 - 3 期,我只是计算 2001 年至 2012 年期间 1 -3 期的平均值。然后我用 2000 年至 2012 年的数据计算期间 4 - 23 的平均值。我编写了一个脚本来执行此操作,但不断收到关于我的数据不存在或不受支持的错误 000732。我在 Arc 中打开了一个网格,它很好。我不确定为什么会收到此错误并包含以下代码。我尝试了多种方法来输入栅格,但得到了同样的错误。
# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *
# Set environment settings
env.workspace = "S:\\MODIS\\DATA_v05\\modis016_0250_ndvi\\us\\"
# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
# Path names for input and output data
path = "S:\\MODIS\\DATA_v05\\modis016_0250_ndvi\\us\\or"
output_path = "B:\\MODIS_NDVI\\Avg_per_period\\avg"
for period in range (1,3):
#MODIS does not have data for the first three periods of 2000. This will calculate an average for the first three periods ignoring the year 2000. It will also place a 0 in front of the single digit to match the file name.
if period <= 3:
period = ("0"+str(period))
grids01 = Raster('"' + path + "01" + period + "ndvius" + '"')
grids02 = Raster('"' + path + "02" + period + "ndvius" + '"')
grids03 = Raster('"' + path + "03" + period + "ndvius" + '"')
grids04 = Raster('"' + path + "04" + period + "ndvius" + '"')
grids05 = Raster('"' + path + "05" + period + "ndvius" + '"')
grids06 = Raster('"' + path + "06" + period + "ndvius" + '"')
grids07 = Raster('"' + path + "07" + period + "ndvius" + '"')
grids08 = Raster('"' + path + "08" + period + "ndvius" + '"')
grids09 = Raster('"' + path + "09" + period + "ndvius" + '"')
grids10 = Raster('"' + path + "10" + period + "ndvius" + '"')
grids11 = Raster('"' + path + "11" + period + "ndvius" + '"')
grids12 = Raster('"' + path + "12" + period + "ndvius" + '"')
#grids = grids01 + ";" + grids02 + ";" + grids03 + ";" + grids04 + ";" + grids05 + ";" + grids06 + ";" + grids07 + ";" + grids08 + ";" + grids09 + ";" + grids10 + ";" + grids11 + ";" + grids12
avg_temp = ('"' + output_path + period + "temp" + '"')
avg = (output_path + period)
outCellStatistics = CellStatistics([grids01, grids02, grids03, grids04, grids05, grids06, grids07, grids08, grids09, grids10, grids11, grids12], "MEAN", "DATA")
outCellStatistics.save(avg_temp)
#This is will place a 0 in front of the single digit to match the file name.
elif period < 10:
period = ("0"+str(period))
grids00 = ('"' + path + "00" + period + "ndvius" + '"')
grids01 = ('"' + path + "01" + period + "ndvius" + '"')
grids02 = ('"' + path + "02" + period + "ndvius" + '"')
grids03 = ('"' + path + "03" + period + "ndvius" + '"')
grids04 = ('"' + path + "04" + period + "ndvius" + '"')
grids05 = ('"' + path + "05" + period + "ndvius" + '"')
grids06 = ('"' + path + "06" + period + "ndvius" + '"')
grids07 = ('"' + path + "07" + period + "ndvius" + '"')
grids08 = ('"' + path + "08" + period + "ndvius" + '"')
grids09 = ('"' + path + "09" + period + "ndvius" + '"')
grids10 = ('"' + path + "10" + period + "ndvius" + '"')
grids11 = ('"' + path + "11" + period + "ndvius" + '"')
grids12 = ('"' + path + "12" + period + "ndvius" + '"')
grids = "[" + grids00 + "," + grids01 + "," + grids02 + "," + grids03 + "," + grids04 + "," + grids05 + "," + grids06 + "," + grids07 + "," + grids08 + "," + grids09 + "," + grids10 + "," + grids11 + "," + grids12 + "]"
avg_temp = (output_path + period + "temp")
avg = (output_path + period)
arcpy.gp.CellStatistics_sa(grids,avg_temp,"MEAN", "DATA")
#These are double digit periods and will match the file name without correction.
else:
period = (str(period))
grids00 = ('"' + path + "00" + period + "ndvius" + '"')
grids01 = ('"' + path + "01" + period + "ndvius" + '"')
grids02 = ('"' + path + "02" + period + "ndvius" + '"')
grids03 = ('"' + path + "03" + period + "ndvius" + '"')
grids04 = ('"' + path + "04" + period + "ndvius" + '"')
grids05 = ('"' + path + "05" + period + "ndvius" + '"')
grids06 = ('"' + path + "06" + period + "ndvius" + '"')
grids07 = ('"' + path + "07" + period + "ndvius" + '"')
grids08 = ('"' + path + "08" + period + "ndvius" + '"')
grids09 = ('"' + path + "09" + period + "ndvius" + '"')
grids10 = ('"' + path + "10" + period + "ndvius" + '"')
grids11 = ('"' + path + "11" + period + "ndvius" + '"')
grids12 = ('"' + path + "12" + period + "ndvius" + '"')
grids = "[" + grids00 + "," + grids01 + "," + grids02 + "," + grids03 + "," + grids04 + "," + grids05 + "," + grids06 + "," + grids07 + "," + grids08 + "," + grids09 + "," + grids10 + "," + grids11 + "," + grids12 + "]"
avg_temp = (output_path + period + "temp")
avg = (output_path + period)
arcpy.gp.CellStatistics_sa(grids,avg_temp,"MEAN", "DATA")