Or, just to be lazy:if not filename.endswith("*.14.tif"):
if not filename.endswith("*.14.tif"):
>>>filename = 'ppt_1970.14.tif' >>>filename.endswith('14.tif') True >>>filename.endswith('*.14.tif') False
Dear Darren,Thank you very much for your reply. Maybe I said something wrong at the beginning. I want to include the files that ends with *.01 to *.12 but exclude *.14.
inRaster = [] # you need to do this outside of the loop for filename in rasterFiles: print("Processing: " + filename) if filename[-6:] in [str(x).zfill(2) + '.tif' for x in xrange(1, 13)]: rasterFiles.append(filename)
# Import system modules import arcpy from arcpy import env from arcpy.sa import * # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # Input data source arcpy.env.workspace = "S:/Work/Risa/Trial_Error/input" # don't use spaces or special characters in path names arcpy.env.overwriteOutput = True # Set output folder OutputFolder = "S:/Work/Risa/Trial_Error/output/" # Loop through a list of files in the workspace rasterFiles = arcpy.ListRasters() # The loop does nothing else but build the list inRaster = [] # you need to do this outside of the loop for filename in rasterFiles: print("Processing: " + filename) if filename.endswith("*.14.tif"): rasterFiles.append(filename) # Now we have a list of the files we want to average, but you only need to calculate the average once, # which means this part should not be in the loop, so we remove indentation outRaster = CellStatistics(rasterFiles, "MEAN", "DATA") # Save the output outRaster.save("S:/Work/Risa/Trial_Error/output/AvgPrecip18.tif") print "Average Calculated!!!" #takes the average and including the file that ends with *.14
# Import system modules import arcpy from arcpy import env from arcpy.sa import * # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # Input data source arcpy.env.workspace = "S:/Work/Risa/Trial_and_Error/input" # don't use spaces or special characters in path names arcpy.env.overwriteOutput = True # Set output folder OutputFolder = "S:/Work/Risa/Trial_and_Error/output/" # Loop through a list of files in the workspace rasterFiles = arcpy.ListRasters() # The loop does nothing else but build the list inRasters = [] # you need to do this outside of the loop for filename in rasterFiles: print("Processing: " + filename) if filename.endswith("14.tif"): inRasters.append(filename) # Now we have a list of the files we want to average, but you only need to calculate the average once, # which means this part should not be in the loop, so we remove indentation outRaster = CellStatistics(inRasters, "MEAN", "DATA") # Save the output outRaster.save("S:/Work/Risa/Trial_and_Error/output/AvgPrecip01.tif") print "Average Calculated!!!"
# Import system modules import arcpy from arcpy import env from arcpy.sa import * # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # Input data source arcpy.env.workspace = "S:/Work/Risa/Trial & Error/input" arcpy.env.overwriteOutput = True # Set output folder OutputFolder = "S:/Work/Risa/Trial & Error/output/" # Loop through a list of files in the workspace rasterFiles = arcpy.ListRasters() # Local variables: for filename in rasterFiles: print("Processing: " + filename) inRaster = arcpy.env.workspace + "/" + filename if filename.endswith("*.14.tif"): inRaster.append(filename) # Process: Cell Statistics outRaster = CellStatistics(inRaster, "MEAN", "DATA") # Save the output outRaster.save("S:/Work/Risa/Trial & Error/output/AvgPrecip01.tif") print "Average Calculated!!!"
inList = [] for filename in rasterFiles: if filename.endswith('14'): inList.append(filename) arcpy.sa.CellStatistics(inList, outRaster, "MEAN", "DATA") # this line was incorrect in your example
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.