I'm trying to transform a bunch of rasters in arcpy according to specific functions to create suitability rasters. This portion of the code is supposed to find all the rasters with interpolated temperature data and transform each as follows:
[0-14] --> 1, [14-23] --> decrease linearly from 1 according to the function, [23-31] --> 0.
import arcpy from arcpy.sa import * arcpy.env.workspace = r"[abspath]" arcpy.env.scratchWorkspace = r"[abspath]\rescale.gdb" aprx = arcpy.mp.ArcGISProject(r"[abspath]\filename.aprx") # Select correct rasters for raster in aprx.listMaps().listLayers(): if raster.isRasterLayer: if 'Temp' in raster.name: if 'Int_Raster' in raster.name: # Set local variables thresholds = [14, 23] bounds = [31.8824, 0] scale = [1, (((-0.7937*thresholds)+25.3051)/((-0.7937*thresholds)+25.3051))] transformation = TfLinear( bounds, bounds, thresholds, 1, thresholds, 0 ) # Rescale the raster rescaledRaster = RescaleByFunction( raster, transformation, scale, scale ) # Save the rescaled raster name = str(raster).replace('Int_Raster','Resc_Raster') rescaledRaster.save(arcpy.env.scratchWorkspace + "\\" + name) print(rescaledRaster.name)
However, this script only creates a single raster called "rescaledRaster" rather than a bunch called "Temp_[identifier]_Resc_Raster", which it's supposed to. It hits the print statement correctly each time so I'm not sure why it isn't creating the individual rasters. I'm using other transformations like TfLogarithm and TfGaussian with other criteria so unfortunately Fuzzy Linear Membership isn't a good option.
EDIT: I have discovered that the single raster the script creates is simply the final raster it's supposed to make, which implies that the previous rasters are getting overwritten rather than saved. I'm not sure why this is the case or why it's still named wrong. Why aren't the rasters saving correctly?