I am trying to calculate mean of selected raster chosen from multiple raster. I have multiple raster file in different month folder, i am trying to select only two raster (e.g For JANUARY : 001_Max_Temper.tif, 001_Min_Temper.tif) from different month folder (JANUARY, FEBRUARY....DECEMBER) and calculate the mean of those selected raster and save it as on same month folder (e.g output name, JANUARY: 001_Mean_Temp).
I have written a code to do this task but i am getting error massage while i am running this code. Below i have attached my code.
import arcpy, os, calendar
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.env.parallelProcessingFactor = "100%"
topWorkspace = r'D:\SWAT-WEATHER-DATA2'
arcpy.env.workspace = topWorkspace
# Get dict of months and month-number (i.e. January = 001, March = 003 etc.)
months = {calendar.month_name[i].upper(): str(i).zfill(3) for i in range(1, 13)} # Get dict of months and month number (i.e. January = 001, March = 003 etc.)
# Step through list of all folders
for folderPath in arcpy.ListWorkspaces():
baseName = os.path.basename(folderPath).upper()
if baseName in months: # Test that subfolder is a month name
monthNumber = months[baseName] # Get month-number for use in output filename
arcpy.env.workspace = folderPath
rasterList = arcpy.ListRasters('*Max_Temper.tif', '*Min_Temper.tif')
# Execute CellStatistics
outCellStatistics = CellStatistics(rasterList, "MEAN", "NODATA")
#Save the output
outRasterName = outCellStatistics, "Mean_Temp_{}.tif".format(monthNumber)
outCellStatistics.save(outRasterName)
#print done
print 'done'
Solved! Go to Solution.
Xander Bakker. Thank you . I had corrected the equation but problem still persist , updated line below attached
ras_EVI = 2.5 * (b02 - b01) / (b02 + (6.0 * b01) - (7.5 * b03) + 1.0)
If the problem or differences remain the best thing you can do is identify some pixels for the bands used in the formula and manually calculate the result and compare this to both results (script and manual) in order to determine which is correct.
Xander Bakker. Thank you very much. I have checked the output as per your suggestion some pixel based calculation. Program generated output are exactly match with pixel wise calculation. Earlier i did with Arc GIS raster calculator. Might be problem with Arc GIS raster calculator output. Hearty gratitude for your valuable guidance.