Composite Bands syntax error

454
4
Jump to solution
04-26-2019 10:32 AM
RyanHowell1
New Contributor III

I have a small image dataset collected by a UAV multispectral camera and I'm trying to make a script tool that merges 4 tiffs into one, for each band (4 blues into one blue, 4 greens into one green, etc) and then use the Composite Bands tool. It runs fine in the Python window (ArcGIS Pro 2.2) but the tool gives me an invalid syntax error and I'm not really sure what the error is.

Here's my script:

outWorkspace = arcpy.GetParameterAsText(0)
cell = arcpy.GetParameterAsText(1)
blue = arcpy.GetParameterAsText(2)
green = arcpy.GetParameterAsText(3)
red = arcpy.GetParameterAsText(4)
nir = arcpy.GetParameterAsText(5)
rededge = arcpy.GetParameterAsText(6)
outName = arcpy.GetParameterAsText(7)

###create empty raster datasets
arcpy.AddMessage("making raster datasets")
blue_T = arcpy.CreateRasterDataset_management(outWorkspace, "blue.tif", cell, '32_BIT_FLOAT', "", 1, "", "", "", "", "")
green_T = arcpy.CreateRasterDataset_management(outWorkspace, "green.tif", cell, '32_BIT_FLOAT', "", 1, "", "", "", "", "")
red_T = arcpy.CreateRasterDataset_management(outWorkspace, "red.tif", cell, '32_BIT_FLOAT', "", 1, "", "", "", "", "")
nir_T = arcpy.CreateRasterDataset_management(outWorkspace, "nir.tif", cell, '32_BIT_FLOAT', "", 1, "", "", "", "", "")
rededge_T = arcpy.CreateRasterDataset_management(outWorkspace, "rededge.tif", cell, '32_BIT_FLOAT', "", 1, "", "", "", "", "")

#####################################################################################
#Merge layers####################################################################
###combine blue layers#####################################################
arcpy.AddMessage("Merging blue...")
bluex = arcpy.Mosaic_management(blue, blue_T)
#################################################################################
#Combine green layers#############################################################
arcpy.AddMessage("Merging green...")
greenx = arcpy.Mosaic_management(green, green_T)
#Combine red layers#############################################################
arcpy.AddMessage("Merging red...")
redx = arcpy.Mosaic_management(red, red_T)
#Combine red layers#############################################################
arcpy.AddMessage("Merging NIR...")
nirx = arcpy.Mosaic_management(nir, nir_T)
#Combine red layers#############################################################
arcpy.AddMessage("Merging red edge...")
rededgex = arcpy.Mosaic_management(rededge, rededge_T)
##############################################################################

#composite bands
arcpy.AddMessage("Running Composite Bands...")
arcpy.CompositeBands_management(bluex;greenx;redex;nirx;rededgex, outWorkspace + outName)

Everything through line 36 works perfectly, so I have 5 complete tiffs, one for each band.

The error is coming in line 40. When I run it in the python window with the actual files and file paths (bypassing the variables) it works. So I assume it's an easy fix and I'm doing something wrong with concatenating my strings or something along those lines.

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

The syntax is odd Composite Bands—Data Management toolbox | ArcGIS Desktop 

it looks like it is expecting a semicolon delimited string as the input

"bluex;greenx;redex;nirx;rededgex

or you could try a comma-delimited list

[bluex, greenx, redex, nirx, rededgex]

but I would try throwing the first, before trying the second

View solution in original post

0 Kudos
4 Replies
RyanHowell1
New Contributor III

Here's the exact error

line 46
arcpy.CompositeBands_management(bluex;greenx;redex;nirx;rededgex, outWorkspace + outName)
^
SyntaxError: invalid syntax
Failed to execute (REtest).

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

The syntax is odd Composite Bands—Data Management toolbox | ArcGIS Desktop 

it looks like it is expecting a semicolon delimited string as the input

"bluex;greenx;redex;nirx;rededgex

or you could try a comma-delimited list

[bluex, greenx, redex, nirx, rededgex]

but I would try throwing the first, before trying the second

0 Kudos
RyanHowell1
New Contributor III

The semicolon delimited string returned the following error:

arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rasters: Dataset blue does not exist or is not supported
Failed to execute (CompositeBands).

However, creating a list and using that in my input ended up working.

arcpy.AddMessage("Running Composite Bands...")
list = [bluex, greenx, redx, nirx, rededgex]
arcpy.CompositeBands_management(list, outWorkspace + "\\" + outName)

Thanks once again for your help Dan.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

No problem,  I will flag the help topic to see if they can provide a better or alternate example based on this thread.  Thanks for getting back Ryan

0 Kudos