I'm trying to reclassify rasters based on standard deviation. I created this code, but I think I'm wrong using "Con"
. I would like to assign value 1 to rasters >= to threshold
and rasters <= to threshold1
and assign NODATA
to the remaining.
This is my code:
import arcpy
ws2 = r"C:\unsupervised_classification\output\raster_tagliati_su_flowacc"
v_name_sc_img = r"C:\unsupervised_classification\output\outliers\{0}_out1.img"
v_name1_sc_img = r"C:\unsupervised_classification\output\outliers\{0}_out2.img"
arcpy.env.workspace = ws2
ras_names = arcpy.ListRasters()
for ras_name in ras_names:
name, ext = os.path.splitext(ras_name)
ras = arcpy.Raster(os.path.join(ws2, ras_name))
mean =float(arcpy.GetRasterProperties_management(ras, "MEAN").getOutput(0).replace(',','.'))
STD=float(arcpy.GetRasterProperties_management(ras, "STD").getOutput(0).replace(',','.'))
threshold_sup=mean + 3* STD
threshold_inf= mean - 3* STD
expression="Con(" + ras + "=>" + str(threshold_sup) + ",1,setnull([ras])"
a= arcpy.gp.RasterCalculator_sa(expression, v_name_sc_img)
expression1="Con(" + ras + "<=" + str(threshold_inf) + ",1,setnull([ras])"
b= arcpy.gp.RasterCalculator_sa(expression1, v_name1_sc_img)
a.save(v_name_sc_img.format(name))
b.save(v_name1_sc_img.format(name))
Arcpy give me this error:
RuntimeError: ERROR 000732: Input Raster: Dataset Con( does not exist or is not supported