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.
<SPAN class="keyword token">import</SPAN> datetime
start <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'start run: %s\n'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>start<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy <SPAN class="punctuation token">,</SPAN>os <SPAN class="punctuation token">,</SPAN>sys
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
<SPAN class="keyword token">import</SPAN> datetime
<SPAN class="keyword token">import</SPAN> glob
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
d1<SPAN class="operator token">=</SPAN><SPAN class="string token">"F:\\DB_test_data\\VAR2\\cldmask\\tt"</SPAN>
CLDMASK <SPAN class="operator token">=</SPAN> glob<SPAN class="punctuation token">.</SPAN>glob<SPAN class="punctuation token">(</SPAN>d1 <SPAN class="operator token">+</SPAN> os<SPAN class="punctuation token">.</SPAN>sep <SPAN class="operator token">+</SPAN> <SPAN class="string token">"*.Aerosol_Cldmask_Land_Ocean-Aerosol_Cldmask_Land_Ocean.tif"</SPAN><SPAN class="punctuation token">)</SPAN>
CLDMASK<SPAN class="punctuation token">.</SPAN>sort<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> CLDMASK
d2<SPAN class="operator token">=</SPAN><SPAN class="string token">"F:\\DB_test_data\\TEST_RAY\\TEST1"</SPAN>
NDVI <SPAN class="operator token">=</SPAN> glob<SPAN class="punctuation token">.</SPAN>glob<SPAN class="punctuation token">(</SPAN>d2 <SPAN class="operator token">+</SPAN> os<SPAN class="punctuation token">.</SPAN>sep <SPAN class="operator token">+</SPAN> <SPAN class="string token">"*A2017001_0530_NDVI_AA.img"</SPAN><SPAN class="punctuation token">)</SPAN>
NDVI<SPAN class="punctuation token">.</SPAN>sort<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> NDVI
d3<SPAN class="operator token">=</SPAN><SPAN class="string token">"F:\\DB_test_data\\VAR2\\IDL\\MOD02HKM\\TEST"</SPAN>
BAND1 <SPAN class="operator token">=</SPAN> glob<SPAN class="punctuation token">.</SPAN>glob<SPAN class="punctuation token">(</SPAN>d3 <SPAN class="operator token">+</SPAN> os<SPAN class="punctuation token">.</SPAN>sep <SPAN class="operator token">+</SPAN> <SPAN class="string token">"*A2017001_0530_006_BAND_1.img"</SPAN><SPAN class="punctuation token">)</SPAN>
BAND1<SPAN class="punctuation token">.</SPAN>sort<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> BAND1
d4<SPAN class="operator token">=</SPAN><SPAN class="string token">"F:\\DB_test_data\\VAR2\\IDL\\MOD02HKM\\TEST"</SPAN>
BAND2 <SPAN class="operator token">=</SPAN> glob<SPAN class="punctuation token">.</SPAN>glob<SPAN class="punctuation token">(</SPAN>d4 <SPAN class="operator token">+</SPAN> os<SPAN class="punctuation token">.</SPAN>sep <SPAN class="operator token">+</SPAN> <SPAN class="string token">"*A2017001_0530_006_BAND_2.img"</SPAN><SPAN class="punctuation token">)</SPAN>
BAND2<SPAN class="punctuation token">.</SPAN>sort<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> BAND2
d4<SPAN class="operator token">=</SPAN><SPAN class="string token">"F:\\DB_test_data\\VAR2\\IDL\\MOD09\\TEST"</SPAN>
BAND3 <SPAN class="operator token">=</SPAN> glob<SPAN class="punctuation token">.</SPAN>glob<SPAN class="punctuation token">(</SPAN>d4 <SPAN class="operator token">+</SPAN> os<SPAN class="punctuation token">.</SPAN>sep <SPAN class="operator token">+</SPAN> <SPAN class="string token">"*A2017001_0530_006_BAND_3.img"</SPAN><SPAN class="punctuation token">)</SPAN>
BAND3<SPAN class="punctuation token">.</SPAN>sort<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> BAND3
d5<SPAN class="operator token">=</SPAN><SPAN class="string token">"F:\\DB_test_data\\VAR2\\IDL\\MOD02HKM\\TEST"</SPAN>
BAND4 <SPAN class="operator token">=</SPAN> glob<SPAN class="punctuation token">.</SPAN>glob<SPAN class="punctuation token">(</SPAN>d5 <SPAN class="operator token">+</SPAN> os<SPAN class="punctuation token">.</SPAN>sep <SPAN class="operator token">+</SPAN> <SPAN class="string token">"*A2017001_0530_006_BAND_4.img"</SPAN><SPAN class="punctuation token">)</SPAN>
BAND4<SPAN class="punctuation token">.</SPAN>sort<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> BAND4
<SPAN class="keyword token">for</SPAN> CL<SPAN class="punctuation token">,</SPAN>ND<SPAN class="punctuation token">,</SPAN>B1<SPAN class="punctuation token">,</SPAN>B2<SPAN class="punctuation token">,</SPAN>B3<SPAN class="punctuation token">,</SPAN>B4 <SPAN class="keyword token">in</SPAN> CLDMASK<SPAN class="punctuation token">,</SPAN>NDVI<SPAN class="punctuation token">,</SPAN>BAND1<SPAN class="punctuation token">,</SPAN>BAND2<SPAN class="punctuation token">,</SPAN>BAND3<SPAN class="punctuation token">,</SPAN>BAND4<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"processing:"</SPAN><SPAN class="operator token">+</SPAN> CL<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"processing:"</SPAN><SPAN class="operator token">+</SPAN> ND<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"processing:"</SPAN><SPAN class="operator token">+</SPAN> B1<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"processing:"</SPAN><SPAN class="operator token">+</SPAN> B2<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"processing:"</SPAN><SPAN class="operator token">+</SPAN> B3<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"processing:"</SPAN><SPAN class="operator token">+</SPAN> B4<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Process: Extract by Mask</SPAN>
tempEnvironment0 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>cellSize
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>cellSize <SPAN class="operator token">=</SPAN> <SPAN class="string token">"MAXOF"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>gp<SPAN class="punctuation token">.</SPAN>ExtractByMask_sa<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>ND<SPAN class="punctuation token">,</SPAN>B1<SPAN class="punctuation token">,</SPAN>B2<SPAN class="punctuation token">,</SPAN>B3<SPAN class="punctuation token">,</SPAN>B4<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> CL<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>cellSize <SPAN class="operator token">=</SPAN> tempEnvironment0
<SPAN class="keyword token">print</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetMessages<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'finished run: %s\n\n'</SPAN> <SPAN class="operator token">%</SPAN> <SPAN class="punctuation token">(</SPAN>datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">-</SPAN> start<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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
. . . . .