<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Storing Rasters in an Array in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591551#M46370</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Kevin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hate to break the news to you, but there is a lot more wrong with the script then what Jim is mentioning. I'll mention a few points:&lt;/SPAN&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;You access the environment setting "&lt;SPAN style="font-style:italic;"&gt;env&lt;/SPAN&gt;" before they have been initialized ("&lt;SPAN style="font-family:courier new;"&gt;from arcpy import env&lt;/SPAN&gt;" is missing)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You set the workspace property of the environment setting using a variable "&lt;SPAN style="font-style:italic;"&gt;Input_Model&lt;/SPAN&gt;", which is not available at that point, since it is obtained from the first parameter later in the script&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You use "gp.overwrite", but gp is not set (you should use the "env" for this purpose and set it properly). The overwrite property does not exist this should be overwriteOutput&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You check out a Spatial Analyst extension, but the tools you're using do not require the sa extension.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You load the Data Management Tools toolbox, but this is really not necessary (was done in previous versions)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You set a variable wse_grid equal to a hard coded string including " + Count", when you probably want to add the count to the string&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;As mentioned before your first argument is read after its first use "Input_Model = arcpy.GetParameterAsText(0)" should move to the top&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You preform an "arcpy.ListRasters". This works on the current workspace. To do this for each folder, you should set the env.workspace for each folder&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Next you&amp;nbsp; loop through the rasters with the statement &lt;SPAN style="font-family:courier new;"&gt;for "wsgridp004" in rasters:&lt;/SPAN&gt;&amp;nbsp; This will not work. Normally you would use something like &lt;SPAN style="font-family:courier new;"&gt;for raster in rasters: &lt;/SPAN&gt;and then access the &lt;SPAN style="font-family:courier new;"&gt;raster &lt;/SPAN&gt;object in the following steps&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;In the arcpy.Clipmanagement statement, you specify strings, when you should specify the variables.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;arcpy.Clipmanagement does not exits, it should be arcpy.Clip_management&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;"FP_Poly" is specified as hard coded string, but should be specified as variable (without double quotes)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Next you add a variable to the array with "array.add", but this variable is never set correctly (the initial wrong value is assigned multiple times)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;In the arcpy.MosaicToNewRaster_management you again specify hard coded strings, when you should specify variables (for instance &lt;SPAN style="font-style:italic;"&gt;Input_Model &lt;/SPAN&gt;should be without quotes.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;The string "array.next" should be a list of rasters separated by semicolons. Since you obtain it from different workspaces, you should include the path for each raster&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;SPAN&gt;To get you started I've included some code. The code however has not been tested...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import os from arcpy import env env.overwriteOutput = True&amp;nbsp; # Argument 1 is the GeoRAS Directory Input_Model = arcpy.GetParameterAsText(0) # Argument 2 is the 100-Year Floodplain FP_Poly = arcpy.GetParameterAsText(1)&amp;nbsp;&amp;nbsp; Count = 0 lstRas = '' rasName = 'wsgridp004'&amp;nbsp; # set workspace for list folders env.workspace = Input_Model Folders = arcpy.ListWorspaces("*", "Folder")&amp;nbsp; for Folder in Folders: &amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = Folder &amp;nbsp;&amp;nbsp;&amp;nbsp; #Find the wsgridp004 Raster &amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters(rasName , "GRID") &amp;nbsp;&amp;nbsp;&amp;nbsp; for raster in rasters: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Count += 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wse_grid = Input_Model + os.sep + "{0}{1}".format(rasName ,Count)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Clip Raster with 100-Yr Floodplain Polygon &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_management(raster, "#", wse_grid, FP_Poly, "0", "ClippingGeometry", "NO_MAINTAIN_EXTENT") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lstRas == '': &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstRas = wse_grid &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstRas = lstRas + ";" + wse_grid&amp;nbsp; #Mosaics Clipped 100-Yr Floodplain Grids print "Mosaicing Clipped Water Surface Grids" arcpy.MosaicToNewRaster_management(lstRas, Input_Model, "wse_100_Yr","NAD_1983_StatePlane_Texas_Central_FIPS_4203_Feet", "32_BIT_FLOAT", "3", "1") print arcpy.GetMessages() print "Complete"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Assuming from the line where you load the toolbox that you are using ArcGIS 10.0 you should look into this topic:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/A_quick_tour_of_ArcPy/000v00000001000000/" rel="nofollow" target="_blank"&gt;A quick tour of ArcPy&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The training.esri.com site offers some Python/arcoy courses that might be interesting:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://training.esri.com/gateway/index.cfm?fa=search.results&amp;amp;searchterm=arcpy&amp;amp;search=Search&amp;amp;CourseTypeID=1&amp;amp;ArcGISVersion=10.0" rel="nofollow" target="_blank"&gt;http://training.esri.com/gateway/index.cfm?fa=search.results&amp;amp;searchterm=arcpy&amp;amp;search=Search&amp;amp;CourseTypeID=1&amp;amp;ArcGISVersion=10.0&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Oct 2013 06:52:49 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2013-10-15T06:52:49Z</dc:date>
    <item>
      <title>Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591549#M46368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;As I am new to this, please forgive me for any glaring errors.&amp;nbsp; I am trying to loop through a series of folders find the "wsgrid004" raster, clip it using a polygon, store the results in an array. Once all the rasters have been processed, mosaic them together.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All I get is a general syntax error, any help would be appreciated!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# Import modules import arcpy&amp;nbsp; # Set enviroment settings env.workspace = Input_Model&amp;nbsp; # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial")&amp;nbsp; # Load Required Toolboxes arcpy.AddToolBox (r"C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Data Management Tools.tbx")&amp;nbsp; #Enable the Overwriting of Existing GeoProcessing Results gp.overwrite = "True"&amp;nbsp; #Local Variables Count = 0 array = arcpy.Array() wse_grid = "wsgridp004 + Count" Folders = arcpy.ListWorspaces("*", "Folder")&amp;nbsp; # Argument 1 is the GeoRAS Directory Input_Model = arcpy.GetParameterAsText(0) # Argument 2 is the 100-Year Floodplain FP_Poly = arcpy.GetParameterAsText(1)&amp;nbsp; # Lists all folders in the Input_Model ListWorkspaces("*","Folder")&amp;nbsp; print "Looking for Sub-Directories" for Folder in Folders: &amp;nbsp;&amp;nbsp;&amp;nbsp; #Find the wsgridp004 Raster &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Finding 100 YR WSEL Raster" &amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters("wsgridp004", "Grid")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for "wsgridp004" in rasters: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Count = Count + 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Clip Raster with 100-Yr Floodplain Polygon &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Clipping Raster" &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clipmanagement("rasters", "#", "wse_grid", "FP_Poly", "0", "ClippingGeometry") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array.add(wse_grid) #Mosaics Clipped 100-Yr Floodplain Grids print "Mosaicing Clipped Water Surface Grids" arcpy.MosaictoNewRaster_Management("array.next", "Input_Model", "wse_100_Yr","NAD_1983_StatePlane_Texas_Central_FIPS_4203_Feet", "32_BIT_FLOAT", "3", "1", " ", " " ) print arcpy.GetMessages() print "Complete"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Oct 2013 15:15:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591549#M46368</guid>
      <dc:creator>Kevin_Smith</dc:creator>
      <dc:date>2013-10-11T15:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591550#M46369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;2 syntax errors:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for "sswgridp004" in rasters&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;should be &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for "sswgridp004" in rasters: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Print "Complete"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;should be&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print "Complete&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Jim&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Oct 2013 15:36:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591550#M46369</guid>
      <dc:creator>JimCousins</dc:creator>
      <dc:date>2013-10-11T15:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591551#M46370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Kevin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hate to break the news to you, but there is a lot more wrong with the script then what Jim is mentioning. I'll mention a few points:&lt;/SPAN&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;You access the environment setting "&lt;SPAN style="font-style:italic;"&gt;env&lt;/SPAN&gt;" before they have been initialized ("&lt;SPAN style="font-family:courier new;"&gt;from arcpy import env&lt;/SPAN&gt;" is missing)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You set the workspace property of the environment setting using a variable "&lt;SPAN style="font-style:italic;"&gt;Input_Model&lt;/SPAN&gt;", which is not available at that point, since it is obtained from the first parameter later in the script&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You use "gp.overwrite", but gp is not set (you should use the "env" for this purpose and set it properly). The overwrite property does not exist this should be overwriteOutput&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You check out a Spatial Analyst extension, but the tools you're using do not require the sa extension.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You load the Data Management Tools toolbox, but this is really not necessary (was done in previous versions)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You set a variable wse_grid equal to a hard coded string including " + Count", when you probably want to add the count to the string&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;As mentioned before your first argument is read after its first use "Input_Model = arcpy.GetParameterAsText(0)" should move to the top&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;You preform an "arcpy.ListRasters". This works on the current workspace. To do this for each folder, you should set the env.workspace for each folder&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Next you&amp;nbsp; loop through the rasters with the statement &lt;SPAN style="font-family:courier new;"&gt;for "wsgridp004" in rasters:&lt;/SPAN&gt;&amp;nbsp; This will not work. Normally you would use something like &lt;SPAN style="font-family:courier new;"&gt;for raster in rasters: &lt;/SPAN&gt;and then access the &lt;SPAN style="font-family:courier new;"&gt;raster &lt;/SPAN&gt;object in the following steps&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;In the arcpy.Clipmanagement statement, you specify strings, when you should specify the variables.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;arcpy.Clipmanagement does not exits, it should be arcpy.Clip_management&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;"FP_Poly" is specified as hard coded string, but should be specified as variable (without double quotes)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;Next you add a variable to the array with "array.add", but this variable is never set correctly (the initial wrong value is assigned multiple times)&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;In the arcpy.MosaicToNewRaster_management you again specify hard coded strings, when you should specify variables (for instance &lt;SPAN style="font-style:italic;"&gt;Input_Model &lt;/SPAN&gt;should be without quotes.&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;The string "array.next" should be a list of rasters separated by semicolons. Since you obtain it from different workspaces, you should include the path for each raster&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;SPAN&gt;To get you started I've included some code. The code however has not been tested...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import os from arcpy import env env.overwriteOutput = True&amp;nbsp; # Argument 1 is the GeoRAS Directory Input_Model = arcpy.GetParameterAsText(0) # Argument 2 is the 100-Year Floodplain FP_Poly = arcpy.GetParameterAsText(1)&amp;nbsp;&amp;nbsp; Count = 0 lstRas = '' rasName = 'wsgridp004'&amp;nbsp; # set workspace for list folders env.workspace = Input_Model Folders = arcpy.ListWorspaces("*", "Folder")&amp;nbsp; for Folder in Folders: &amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = Folder &amp;nbsp;&amp;nbsp;&amp;nbsp; #Find the wsgridp004 Raster &amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters(rasName , "GRID") &amp;nbsp;&amp;nbsp;&amp;nbsp; for raster in rasters: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Count += 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wse_grid = Input_Model + os.sep + "{0}{1}".format(rasName ,Count)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Clip Raster with 100-Yr Floodplain Polygon &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_management(raster, "#", wse_grid, FP_Poly, "0", "ClippingGeometry", "NO_MAINTAIN_EXTENT") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages() &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lstRas == '': &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstRas = wse_grid &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstRas = lstRas + ";" + wse_grid&amp;nbsp; #Mosaics Clipped 100-Yr Floodplain Grids print "Mosaicing Clipped Water Surface Grids" arcpy.MosaicToNewRaster_management(lstRas, Input_Model, "wse_100_Yr","NAD_1983_StatePlane_Texas_Central_FIPS_4203_Feet", "32_BIT_FLOAT", "3", "1") print arcpy.GetMessages() print "Complete"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Assuming from the line where you load the toolbox that you are using ArcGIS 10.0 you should look into this topic:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/A_quick_tour_of_ArcPy/000v00000001000000/" rel="nofollow" target="_blank"&gt;A quick tour of ArcPy&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The training.esri.com site offers some Python/arcoy courses that might be interesting:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://training.esri.com/gateway/index.cfm?fa=search.results&amp;amp;searchterm=arcpy&amp;amp;search=Search&amp;amp;CourseTypeID=1&amp;amp;ArcGISVersion=10.0" rel="nofollow" target="_blank"&gt;http://training.esri.com/gateway/index.cfm?fa=search.results&amp;amp;searchterm=arcpy&amp;amp;search=Search&amp;amp;CourseTypeID=1&amp;amp;ArcGISVersion=10.0&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 06:52:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591551#M46370</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2013-10-15T06:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591552#M46371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Xander,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the suggestions, the first round of code was a rough. After Jim's help, I went back and spent a fair amount of time going back through the code and making changes that addressed a fair amount your points. However, I was having a rough time with the list rasters and array but you gave excellent tips.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 13:14:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591552#M46371</guid>
      <dc:creator>Kevin_Smith</dc:creator>
      <dc:date>2013-10-15T13:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591553#M46372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Xander,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for you help, the advice about environments and looping was extremely helpful. I have run into another problem. I keep on getting the below error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: Failed to execute. Parameters are not valid. ERROR 000157: Input and target dataset should have the same number of bands Failed to execute (MosaicToNewRaster).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I run the tool in ArcMap with the exact same settings, the tool completes no problems. Any thoughts?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Import modules
import arcpy
import os

# Set enviroment settings
from arcpy import env
env.overwriteOutput = True


# Argument 1 is the GeoRAS Directory
Input_Model = arcpy.GetParameterAsText(0)
# Argument 2 is the 100-Year Floodplain
FP_Poly = arcpy.GetParameterAsText(1)

#Local Variables
Count = 0
P004 = 'wsgridp004'
lstRstr = ' ' 

#Set Workspace for list folders
env.workspace = Input_Model
Folders = arcpy.ListWorkspaces("*", "Folder")

print "Looking for Sub-Directories"
for Folder in Folders:
&amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = Folder
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Find the wsgridp004 Raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Finding 100 YR WSEL Raster"
&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters(P004, "Grid")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for raster in rasters:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Count = Count + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wse_grid = Input_Model + os.sep + "{0}{1}".format(P004 ,Count)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Clip Raster with 100-Yr Floodplain Polygon
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Clipping Raster"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_management(raster, "#", "wse_grid", FP_Poly, "0", "ClippingGeometry")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lstRstr == '':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstRstr = wse_grid
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lstRstr = lstRstr + ";" + wse_grid
#Mosaics Clipped 100-Yr Floodplain Grids
print "Mosaicing Clipped Water Surface Grids"
arcpy.MosaicToNewRaster_management(lstRstr, Input_Model,"wse_100_Yr"," ", "32_BIT_FLOAT", "3", "1", "MAXIUM", "FIRST")
print arcpy.GetMessages()
print "Complete"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:24:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591553#M46372</guid>
      <dc:creator>Kevin_Smith</dc:creator>
      <dc:date>2021-12-12T01:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591554#M46373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It is telling you the problem here: Input and target dataset should have the same number of bands &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When you run a mosaic through ArcCatalog, it will default to the number of bands in your input datasets. In your script you have defined it explicitly to 3 bands, such as in an RGB image, even though it appears you are using grid rasters which have only one band.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 20:11:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591554#M46373</guid>
      <dc:creator>TimBarnes</dc:creator>
      <dc:date>2013-10-15T20:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591555#M46374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Kevin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tim is right about the number of bands which should be the same for all raster you want to mosaic together. The syntax of &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000098000000"&gt;Mosaic To New Raster (Data Management)&lt;/A&gt;&lt;SPAN&gt; is this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:courier new;"&gt;MosaicToNewRaster_management (input_rasters, output_location, raster_dataset_name_with_extension, {coordinate_system_for_the_raster}, {pixel_type}, {cellsize}, number_of_bands, {mosaic_method}, {mosaic_colormap_mode})&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In my script this is what is assigned:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family:courier new;"&gt;&lt;BR /&gt;input_rasters = lstRas&lt;BR /&gt;output_location = Input_Model&lt;BR /&gt;raster_dataset_name_with_extension = "wse_100_Yr"&lt;BR /&gt;{coordinate_system_for_the_raster} = "NAD_1983_StatePlane_Texas_Central_FIPS_4203_Feet"&lt;BR /&gt;{pixel_type} = "32_BIT_FLOAT"&lt;BR /&gt;&lt;STRONG&gt;{cellsize} = "3"&lt;BR /&gt;number_of_bands = "1"&lt;/STRONG&gt;&lt;BR /&gt;{mosaic_method} = omitted&lt;BR /&gt;{mosaic_colormap_mode} = omitted&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was taken from your original settings. So you are executing a mosaic using a &lt;/SPAN&gt;&lt;STRONG&gt;cell size of 3&lt;/STRONG&gt;&lt;SPAN&gt; and &lt;/SPAN&gt;&lt;STRONG&gt;1 band&lt;/STRONG&gt;&lt;SPAN&gt;. Verify your input rasters. If the settings are not correct, change them in the script. If the number of bands in the rasters is not the same, you will not be able to mosaic them together.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Oct 2013 05:37:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591555#M46374</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2013-10-16T05:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591556#M46375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry for the delay in my response, you know how it goes always a thousand different things to do. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I originally set the number of bands by looking at raster data set properties. I thought maybe I had a rouge raster with a different amount of bands, so I went back and checked every input raster and they are all the same. (See below)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]28511[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts??&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Oct 2013 13:11:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591556#M46375</guid>
      <dc:creator>Kevin_Smith</dc:creator>
      <dc:date>2013-10-22T13:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591557#M46376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Any thoughts??&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Kevin,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had a closer look at the script, and noticed you changed a few things.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;lstRstr = &lt;STRONG&gt;' '&lt;/STRONG&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;should be: &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;lstRstr = &lt;STRONG&gt;''&lt;/STRONG&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You initially set the variable to single space, when it should be an empty string. Later the code checks for an empty string and will not find it. This causes the list of rasters to contain a "space" for the first raster name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.Clip_management(raster, "#", &lt;STRONG&gt;"wse_grid"&lt;/STRONG&gt;, FP_Poly, "0", "ClippingGeometry")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;should be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.Clip_management(raster, "#", &lt;STRONG&gt;wse_grid&lt;/STRONG&gt;, FP_Poly, "0", "ClippingGeometry")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this case the output raster will have a unique name for each raster and not always "wse_grid".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.MosaicToNewRaster_management(lstRstr, Input_Model,"wse_100_Yr"," ", "32_BIT_FLOAT", "3", "1", "&lt;STRONG&gt;MAXIUM&lt;/STRONG&gt;", "FIRST") &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;should be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.MosaicToNewRaster_management(lstRstr, Input_Model,"wse_100_Yr"," ", "32_BIT_FLOAT", "3", "1", "&lt;STRONG&gt;MAXIMUM&lt;/STRONG&gt;", "FIRST") &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The provided &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;mosaic_method&lt;/SPAN&gt;&lt;SPAN&gt; was not valid due to typo. I also notice that you blanked the output coordinate system. This may not be a problem if you environment settings are correct.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try again and see what happens.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Oct 2013 13:38:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591557#M46376</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2013-10-22T13:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Storing Rasters in an Array</title>
      <link>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591558#M46377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;D'oh, I cannot believe that I missed spelling and variable errors. Although, I would have missed the spacing in the quotes. I appreciate everyone's help, the script is up and running as we speak! Once again, many thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Oct 2013 20:06:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/storing-rasters-in-an-array/m-p/591558#M46377</guid>
      <dc:creator>Kevin_Smith</dc:creator>
      <dc:date>2013-10-22T20:06:32Z</dc:date>
    </item>
  </channel>
</rss>

