I am using ERDAS Imagine 2013 and am trying to create a Python script that takes lists created in another script containing the path to each scene's raw data folder and base image ID's (for example LC80230282013183LGN00). I then use a for-loop to go to each data folder, selecting the layers to stack to produce my stacked images. Also, I'm working with ETM+ and OLI data so I have a conditional statement to determine which bands to stack (1-7 for OLI and 1-5 & 7 for ETM+). What I have so far will stack the layers for the first data folder in the list, but then I get an error when it attempts to stack layers in the next folder in the list. I'm fairly inexperienced with Python and coding in general and I feel like either my logic is wrong or I'm just way off with my code.
What I have:
from imagine import modeler
from getpath import imageName, imagePath, outputPathStack
m = modeler.Model()
numImages = len(imageName)
for i in range (0,numImages):
#check for landsat 8 image
if "LC8" in str(imageName[i]):
ri1 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B1.tif")
ri2 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B2.tif")
ri3 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B3.tif")
ri4 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B4.tif")
ri5 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B5.tif")
ri6 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B6.tif")
ri7 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B7.tif")
StackBands = m.StackLayers(ri1, ri2, ri3, ri4, ri5, ri6, ri7)
ro = m.RasterOutput(StackBands, outputPathStack + \
imageName[i] + "_stack.img")
#check for landsat 7 image
elif "LE7" in str(imageName[i]):
ri1 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B1.tif")
ri2 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B2.tif")
ri3 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B3.tif")
ri4 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B4.tif")
ri5 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B5.tif")
ri6 = m.RasterInput(imagePath[i] + "/" + imageName[i] + "_B7.tif")
StackBands = m.StackLayers(ri1, ri2, ri3, ri4, ri5, ri6)
ro = m.RasterOutput(StackBands, outputPathStack + \
imageName[i] + "_stack.img")
m.Execute()
The error I get is:
File "C:\Workspace\stacklayers.py", line 35, in
m.Execute()
RuntimeError: erdas::sblib::Operator::SetErrorMessage failed
Spatial Model failed in Raster Output 2. Error: erdas::sbsupportlib::LayerOperator::OnExecute failed
erdas::sbsupportlib::LayerOpOnExecute::WriteBlock failed
Bad response from exchange.
Best Answer
As commented by the asker: