I have multiple NetCDF files which were converted into tif files using the tools Make NetCDF Raster Layer & Copy Raster tool in ArcGIS Pro 2.6. As output, I now have multiple tif files with many bands inside it. Here is a screenshot for reference.
As I have multiple tif files of such kind, I am now trying to come up with a python script that can composite only certain bands.
So if the total number of bands in a tif file is 365 I only want to composite Band_167 to Band_193.
Here is the snippet that I have worked out so far however, it gives me an error : ERROR 000732: Input Rasters: Dataset Band_167 does not exist or is not supported
import arcpy
import os
arcpy.env.workspace = r'C:\Vikhyat\Test\*.tif'
Input = arcpy.env.workspace
Output = r'C:\Vikhyat\Data\Stack'
for img in Input:
name = os.path.join(Output, img[0].split("_")[0] + ".tif")
arcpy.CompositeBands_management('Band_167;Band_168;Band_169;Band_170', name)
print('Finished')
Best Answer
The code you need is this, see how I build a list of full path to your raster\band.
It's good practise when developing code to put in print() statements so you can see what it is actually creating, for example your original code was creating
.tif.tif
as the output file name.This tool did not seem to be honouring workspace so this is why I build the full path name.