Hi, I'm new to Python, and have been having problems with conditional statements. There are two issues:
1) One of my conditions is that anything <5 = 0. When I do this, anything with a negative number returns as 'no data' instead of 0
2) When the returning value refers back to the input raster, the syntax fails. The statement works in Raster Calculator, but it seems like I should be using different syntax in Python, but can't find any documentation about this.
Variables
inRas1 = arcpy.Raster(r"C:\Data\WorldClim\Minimum\tmin1.tif")
minA = float(5)
minB = float(15)
maxC = float(23)
maxD = float(27)
divA = (minB - minA)
divB = (maxD - maxC)
The full statement is as follows (line breaks for clarity - not in actual script!):
outCon1 = Con((inRas1 > minB) & (inRas1 < maxC),1,
Con((inRas1 < minA) & (inRas1 > maxD),0,
Con((inRas1 > minA) & (inRas1 < minB),(inRas1 – minA)/divA,
Con((inRas1 > maxC) & (inRas1 < maxD),(maxD - inRas1)/divB))))
I simplified it to this and it worked:
outCon1 = Con((inRas1 > minB) & (inRas1 < maxC),(minA/divA))
However, when I expanded it out to this, it didn't:
outCon1 = Con((inRas1 > minB) & (inRas1 < maxC),(inRas1 – minA)/divA)
So, am I better off doing this as an IF statement?
Alternatively, do you know a better way of carrying out a trapezoidal membership function? The built in fuzzy tools seem to have everything but this!
Thanks in advance!