Arcpy create composite images from several single band tifs

Discussion created by JoshAhmed on Feb 5, 2014
Latest reply on Apr 29, 2014 by anewby

I have a folder containing 7 tif rasters that I would like to combine into one composite tif. I have to do this for many images so I have written a python script to speed up to process. However, I'm having some trouble collecting all of the bands from the folder and creating a composite. Any help would be much appreciated.

import arcpy, sys, os
from arcpy import env
from import *
arcpy.env.overwriteOutput = True #set the script to overwrite files
#the path to where the images are stored - will need to change for each set of images as the end folders are different
path_images = "J:/Proj/Annual_time_series/Landsat Images/1987/1_001_070/"
for root, dirs, files in os.walk(path_images):
    for name in files:
        beni87 = os.path.join(root,name)
        if beni87.endswith[('B10.TIF', 'B20.TIF', 'B30.TIF', 'B40.TIF', 'B50.TIF', 'B60.TIF', 'B70.TIF')] == True: #collect band 1,2 and 3 image
            tilename = name[0:-7] #remove the band number and .tif from the end of each image to be renamed
            print tilename + "being processed."
            #the list of banded images need to be put here, or the file containing the list needs to be put here
            in_rasters = path_images + name #input the bands from the file
            out_raster = path_images + tilename + "composite.tif" #insert the name of the image between the quotation marks
            #start composite bands processing
            arcpy.CompositeBands_management(in_rasters, out_raster)