I have one problem regarding call different file in a single for loop. Basically, I want to mask six images(NDVI, BAND1....BAND5 of Modis sensor) by a single cloud mask file. For every time step, it will be changed (The cloud mask image plus 6 images). But the code is not working, in this case, I am not sure how to write this function but I try to write this code.
@
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
d4="F:\\DB_test_data\\VAR2\\IDL\\MOD09\\TEST"
BAND3 = glob.glob(d4 + os.sep + "*A2017001_0530_006_BAND_3.img")
BAND3.sort()
print BAND3
d5="F:\\DB_test_data\\VAR2\\IDL\\MOD02HKM\\TEST"
BAND4 = glob.glob(d5 + 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)
After that, I want to extract the pixels wise NDVI value(categorize NDVI range like this(please look below)) and their corresponding band's pixel values and it will be saved in a table(Three tables based on NDVI categories)at a .text format in every time step of for loop. I am confused about how to write this code please help me to resolve this matter.
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.50<NDVI (Category 3)
NDVI band1 band2 band4 band5
Please look at this matter
. . . . .
Please help me, anyone, to resolve this matter, I am waiting for Replies.
I am trying to write this code but getting some error in the loop please see the error. If anybody knows how to solve this issue then give me a suggestion to resolve this issue.
Traceback (most recent call last):
File "F:\DB_test_data\python_script\DB_TEST2.py", line 117, in <module>
for o,x,y,z in [(o,x,y,z) for o in Band1_mask1 for x in Band2_mask2 for y in Band3_mask3 for z in Band4_mask4]:
TypeError: 'geoprocessing server result object' object is not iterable
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 o,x,y,z in [(o,x,y,z)for CL in CLDMASK for ND in NDVI for B1 in BAND1 for B2 in BAND2 for B3 in BAND3 for B4 in 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)