Hi,
I am trying to extract the rasters by mask in batches using Python in ArcGIS 10.3. When I extracted one sample raster data by mask using the Extract by Mask tool in ArcToolbox, the result is what I expected. But I have too much raster data to extracted one by one, so I used this code to achieve it:
<SPAN class="keyword token">import</SPAN> arcpy
<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="comment token">#environment settings</SPAN>
env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"E:/MGH_data/MGH_newLandsat/Bulk Order 1043142/NDVI_TIFF"</SPAN>
rasterList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"tif"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#out put path</SPAN>
output_path <SPAN class="operator token">=</SPAN> <SPAN class="string token">"E:/MGH_data/MGH_newLandsat/Bulk Order 1043142/NDVI_Clip/"</SPAN>
<SPAN class="comment token">#mask shapfile</SPAN>
inMaskData <SPAN class="operator token">=</SPAN> <SPAN class="string token">"F:/MsAcademicPaper/MaGuiHe_HJL/MGH_huangjingling/basin_area.shp"</SPAN>
<SPAN class="keyword token">for</SPAN> raster <SPAN class="keyword token">in</SPAN> rasterList<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> raster
inRaster <SPAN class="operator token">=</SPAN> raster
<SPAN class="comment token"># Execute ExtractByMask</SPAN>
outExtractByMask <SPAN class="operator token">=</SPAN> ExtractByMask<SPAN class="punctuation token">(</SPAN>inRaster<SPAN class="punctuation token">,</SPAN> inMaskData<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Save the output</SPAN>
outname <SPAN class="operator token">=</SPAN> output_path <SPAN class="operator token">+</SPAN> inRaster
outExtractByMask<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>outname<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>
when I execute the above commands in Python window, there are some abnormal values in the nodata area in the results. Here is the value range of the result with abnormal values (the low value):

So I was wondering which step is wrong. So I tried to use this code to extract one sample raster data, and I just ran the code only before saving the output, which means it will not to execute the code that is used to save the output (the last two lines of the code), and the result is correct, without any abnormal values. Here is the value range of the correct raster result:

So I guess the problem is from the Save output raster step. But I checked the code many times and still have no idea to solve it. Anybody knows what's going wrong? I do appreciate your help.
Thanks!