Hi All,
I have multiple NetCDF files which were converted into tiff files using the tools Make NetCDF Raster Layer & Copy Raster tool in ArcGIS Pro 2.6. As output, I now have multiple tiff files in a folder with many bands inside the tiff files. Here is a screenshot for reference.
As I have multiple tiff 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 tiff 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 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds. Failed to create raster dataset Failed to execute (CompositeBands).
import arcpy
import os
arcpy.env.workspace = r'C:\Vikhyat\Test'
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('Rainfall__Clim_Pred_LRF_New_RF25_IMD0p252001.tif/Band_167;Rainfall__Clim_Pred_LRF_New_RF25_IMD0p252001.tif/Band_168;Rainfall__Clim_Pred_LRF_New_RF25_IMD0p252001.tif/Band_169;Rainfall__Clim_Pred_LRF_New_RF25_IMD0p252001.tif/Band_170', name)
print('Finished')
I have tried to use arcpy.CompositeBands_management on individual bands which are in tiff format and it worked successfully.
Hence, any inputs on what I might be missing would be helpful.
Solved! Go to Solution.
for img in Input:
This does nothing. You need ListRasters to act on the workspace.
And this line will accomplish nothing unless the previous line provides a raster
name = os.path.join(Output, img[0].split("_")[0] + ".tif")
You would be better off providing the raster bands you need and providing an output filename.
If you need to automate this for other folders, can you provide the rules that you will use to assemble the needed bands.
for img in Input:
This does nothing. You need ListRasters to act on the workspace.
And this line will accomplish nothing unless the previous line provides a raster
name = os.path.join(Output, img[0].split("_")[0] + ".tif")
You would be better off providing the raster bands you need and providing an output filename.
If you need to automate this for other folders, can you provide the rules that you will use to assemble the needed bands.
Thank you for suggesting to use the list raster's method, it worked and I was also able to format output file name.
The ListRasters method worked however, the issue that I am having now is that output is getting overwritten as I had hardcoded which raster file bands I want to composite. Here is the snippet for reference.
I tried to use only Band name like Band_167, Band_168 etc however, it gives me an error :
I am not sure what exactly to put in parameters so that it composite individual file bands.
ERROR 000732: Input Rasters: Dataset Band_167 does not exist or is not supported
arcpy.CompositeBands_management('Rainfall__Clim_Pred_LRF_New_RF25_IMD0p252001.tif/Band_167;Rainfall__Clim_Pred_LRF_New_RF25_IMD0p252001.tif/Band_168;Rainfall__Clim_Pred_LRF_New_RF25_IMD0p252001.tif/Band_169;Rainfall__Clim_Pred_LRF_New_RF25_IMD0p252001.tif/Band_170', name)
You still need the full path to the raster and/or set the environment to the folder that contains the rasters as you did previously.