I am having issues with continuously changing the values of pixels within a single band of a multiband raster using python 2.7. Essentially, what I am trying to do is continuously change (increment) the pixel values of a single band based on variables drawn from 2 lists that are used in the nested loop. I've included some code to help understand what I'm doing.
import arcpy import os from arcpy.sa import * import math arcpy.CheckOutExtension('spatial') ConstantList = [2.1, 1.6] TimeStep = ["4h", "8h", "12h", "16h", "20h", "24h"] multiband = "Path:\\to\\my\\multibandraster.tif\\" arcpy.env.workspace = multiband bands = [Raster(os.path.join(multiband, b)) for b in arcpy.ListRasters()] count = 1 for constant in ConstantList: for time in TimeStep: temperature = Raster("Path:\\to\\temperatureRasters\\" + time + "_1_1971.tif" bands = Con(((temperature > 2.5) & (temperature < 35)), bands + some equation, bands) bands.save("Path:\\to\\output" + str(count) + ".tif") count = count + 1 arcpy.CheckInExtension('spatial')
Using this code, I get a raster with all pixels = NoData. If I remove the 'time' for loop (for time in TimeStep:....) I can get the correct values, but only for one timestep. Why would including the 'time' for loop give me a raster with NoData, and how can I fix it?
Also, I should mention that when I remove the 'time' for loop, the values of bands during the execution of the second constant in the constant list, are wrongly added to bands values calculated during the execution of the first constant. At the start of the second constant, the values of bands should be reset to the original values of the multiband raster.