# Gather files
files = [file for file in os.listdir(inDir) if file.endswith('.kea')]
bandDefns = []
explist = []
for file in files:
# Define each single file band
bandDefns.append(BandDefn('b' + str(files.index(file)), os.path.join(inDir, file), 1))
# Make a list of the file number (i.e. [1,2,3,4,5...])
explist.append('b' + str(files.index(file)))
gdalformat = 'KEA'
datatype = rsgislib.TYPE_32FLOAT
# Create the expression by joining the band bumber to a 'b' for each file
# and dividing by the total number of files
expression = str(' + ').join(explist).join('()') + '/' + str(len(explist))
imagecalc.bandMath(outputImage, expression, gdalformat, datatype, bandDefns)