我有一个问题,关于在单个for循环中调用不同的文件。基本上,我想通过一个云遮罩文件遮罩六个图像(NDVI,Band1 ... Modis传感器的BAND5)。对于每个时间步,它将被更改(云蒙版图像加6张图像)。但是代码不起作用,在这种情况下,我不确定如何编写此函数,但是我尝试编写此代码。
在那之后,我想提取像素的NDVI值(将NDVI范围分类为此类(请看下面))及其对应波段的像素值,并将其保存在一个表(基于NDVI类别的三个表)中for循环的每个时间步都使用.text格式。我对如何编写此代码感到困惑,请帮助我解决此问题。
表格:
0.10<NDVI<0.20 (Category 1)
NDVI band1 band2 band4 band5
0.190 0.311 2.11601 0.1000 0.3377
0.199 0.312 2.1100 0.1007 0 .3375
. . . . .
0.20<NDVI<0.50 (Category 2)
NDVI band1 band2 band4 band5
0.299 0.322 2.1200 0.1007 0 .456
. . . . .
0.50<NDVI (Category 3)
NDVI band1 band2 band4 band5
0.399 0.342 2.1200 0.1007 0 .356
. . . . .
代码:
`import datetime
start = datetime.datetime.now()
print 'start run: %s\n' % (start)
import arcpy ,os ,sys
from arcpy import env
from arcpy.sa import *
import datetime
import glob
arcpy.env.overwriteOutput = True
d1="F:\\DB_test_data\\VAR2\\cldmask\\tt"
CLDMASK = glob.glob(d1 + os.sep + "*.Aerosol_Cldmask_Land_Ocean-Aerosol_Cldmask_Land_Ocean.tif")
CLDMASK.sort()
print CLDMASK
d2="F:\\DB_test_data\\TEST_RAY\\TEST1"
NDVI = glob.glob(d2 + os.sep + "*A2017001_0530_NDVI_AA.img")
NDVI.sort()
print NDVI
d3="F:\\DB_test_data\\VAR2\\IDL\\MOD02HKM\\TEST"
BAND1 = glob.glob(d3 + os.sep + "*A2017001_0530_006_BAND_1.img")
BAND1.sort()
print BAND1
d4="F:\\DB_test_data\\VAR2\\IDL\\MOD02HKM\\TEST"
BAND2 = glob.glob(d4 + os.sep + "*A2017001_0530_006_BAND_2.img")
BAND2.sort()
print BAND2
d5="F:\\DB_test_data\\VAR2\\IDL\\MOD09\\TEST"
BAND3 = glob.glob(d5 + os.sep + "*A2017001_0530_006_BAND_3.img")
BAND3.sort()
print BAND3
d6="F:\\DB_test_data\\VAR2\\IDL\\MOD02HKM\\TEST"
BAND4 = glob.glob(d6 + os.sep + "*A2017001_0530_006_BAND_4.img")
BAND4.sort()
print BAND4
for CL,ND,B1,B2,B3,B4 in CLDMASK,NDVI,BAND1,BAND2,BAND3,BAND4:
print ("processing:"+ CL)
print ("processing:"+ ND)
print ("processing:"+ B1)
print ("processing:"+ B2)
print ("processing:"+ B3)
print ("processing:"+ B4)
# Process: Extract by Mask
tempEnvironment0 = arcpy.env.cellSize
arcpy.env.cellSize = "MAXOF"
arcpy.gp.ExtractByMask_sa([ND,B1,B2,B3,B4], CL)
arcpy.env.cellSize = tempEnvironment0
print arcpy.GetMessages()
print 'finished run: %s\n\n' % (datetime.datetime.now() - start)`