HI,
Can somebody help me to read one file at a time in the following raster list? I want to match a condition and then read the corresponding raster file from the "rasterlist". My code below cannot achieve what I want.
Any help is appreciated.
Thanks in advance.
year<SPAN class="operator token">=</SPAN><SPAN class="number token">2010</SPAN>
month<SPAN class="operator token">=</SPAN><SPAN class="number token">10</SPAN>
week<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN>
rasterlist <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>
Week_1_Sum1981_10_Crawford<SPAN class="punctuation token">.</SPAN>tif
Week_1_Sum1982_10_Crawford<SPAN class="punctuation token">.</SPAN>tif
<SPAN class="punctuation token">.</SPAN>
Week_1_Sum2016_10_Crawford<SPAN class="punctuation token">.</SPAN>tif
Week_2_Sum1981_10_Crawford<SPAN class="punctuation token">.</SPAN>tif
<SPAN class="punctuation token">.</SPAN>
Week_2_Sum2016_10_Crawford<SPAN class="punctuation token">.</SPAN>tif
<SPAN class="punctuation token">.</SPAN>
Week_5_Sum2016_10_Crawford<SPAN class="punctuation token">.</SPAN>tif<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> file <SPAN class="keyword token">in</SPAN> fmaskrasters<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> fnmatch<SPAN class="punctuation token">.</SPAN>fnmatch<SPAN class="punctuation token">(</SPAN>file<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Week_'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>week<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_Sum'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>year<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_'</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>month<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'_Crawford.tif'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="punctuation token">(</SPAN>file<SPAN class="punctuation token">)</SPAN>
raster <SPAN class="operator token">=</SPAN> rasterlist<SPAN class="punctuation token">[</SPAN>file<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>