I'm trying to do Map Algebra on a bunch of rasters by iterating through a for loop and saving them in an empty geodatabase. However, they aren't saving properly. Only the last raster is created and it is named "rescaledRaster" rather than the outName. Here's the code:
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">import</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> os
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">from</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>sa <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">import</SPAN> <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">*</SPAN>
arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>env<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>workspace <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> r<SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 13px;">"[abspath]"</SPAN>
arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>env<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>scratchWorkspace <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> r<SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 13px;">"[abspath]\rescale.gdb"</SPAN>
aprx <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>mp<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>ArcGISProject<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN>r<SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 13px;">"[abspath]\filename.aprx"</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit; font-size: 13px;"># Select correct interpolated rasters</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">for</SPAN> lyr <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">in</SPAN> aprx<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>listMaps<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>listLayers<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">if</SPAN> lyr<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>isRasterLayer<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">if</SPAN> <SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 13px;">'Temp'</SPAN> <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">in</SPAN> lyr<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">:</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">if</SPAN> <SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 13px;">'Int_Raster'</SPAN> <SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">in</SPAN> lyr<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">:</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit; font-size: 13px;"># Set local variables</SPAN>
raster <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> Raster<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN>lyr<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>dataSource<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN>
thresholds <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> <SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">14</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">23</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN>
bounds <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> <SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">14</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">23</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN>
scale <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> <SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">0.496714</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN>
transformation <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> TfLinear<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN> bounds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> bounds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> thresholds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> thresholds<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> <SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">0</SPAN> <SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN>
outName <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> arcpy<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>env<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>scratchWorkspace <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">+</SPAN> <SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 13px;">"\\"</SPAN> <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">+</SPAN> raster<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>replace<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 13px;">'Int_Raster'</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN><SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 13px;">'Resc'</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit; font-size: 13px;"># Rescale the raster</SPAN>
rescaledRaster <SPAN class="" style="color: #a67f59; background: rgba(255, 255, 255, 0.5); border: 0px; font-weight: inherit; font-size: 13px;">=</SPAN> RescaleByFunction<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN> raster<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> transformation<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> scale<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">0</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">,</SPAN> scale<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">[</SPAN><SPAN class="" style="color: #990000; border: 0px; font-weight: inherit; font-size: 13px;">1</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">]</SPAN> <SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN>
<SPAN class="" style="color: slategray; border: 0px; font-weight: inherit; font-size: 13px;"># Save the rescaled raster</SPAN>
rescaledRaster<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>save<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN>outName<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN> #NOT WORKING!!!
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN>rescaledRaster<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>isTemporary<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px; font-weight: inherit; font-size: 13px;">print</SPAN><SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN>rescaledRaster<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN>name<SPAN class="" style="color: #999999; border: 0px; font-weight: inherit; font-size: 13px;">)</SPAN><SPAN class="" style="border-width: 0px 1px 0px 0px; border-style: initial solid initial initial; border-color: initial #999999 initial initial; font-weight: inherit;"></SPAN><CODE><SPAN class="" style="color: #101094; border: 0px; font-weight: inherit; font-size: 13px;"> </SPAN>
The print statements seem correct each time; .isTemporary comes out False and .name returns the outName. Despite this, the output rasters keep getting overwritten.
I also tried outName = os.path.join(arcpy.env.scratchWorkspace, raster.name.replace('Int_Raster','Resc')) as well and that didn't work either.