Hello all,
I am trying to convert a nested IF statement from Excel into Python via the Field Calculator in ArcMap. The data is wind data which has two fields: U and V; and the calculation is to be entered in the DIR field. These are vectors can be applied with triganometry to create wind direction in degrees. In Excel, the DIR field has the following formula:
=IF(D2>0,((180/PI())*ATAN(C2/D2)+180),IF(AND(C2<0,D2<0),((180/PI())*ATAN(C2/D2)),IF(AND(C2>0,D2<0),((180/PI())*ATAN(C2/D2)+360),IF(AND(D2=0,C2>0),270,IF(AND(D2=0,C2<0),90,0)))))
...where column C is the U field and column D is the V field.
I've been playing all day with this and so far, I have the following:
codeblock:
def winddir(DIR):
if !V! > 0:
!DIR! = ((180/math.pi)*math.atan(!U!/!V!)+180)
elif !U! < 0 and !V! < 0:
!DIR! = ((180/math.pi)*math.atan(!U!/!V!))
elif !U! > 0 and V < 0:
!DIR! = ((180/math.pi)*math.atan(!U!/!V!)+360)
elif !V! == 0 and !U! > 0:
!DIR! = 270
elif !V! == 0 and !U! < 0:
!DIR! = 90
DIR =
winddir(DIR)
I keep getting the generic error:
ERROR 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 2)
I'm really pulling my hair out with this as I've tried tweaking the syntax but I cannot resolve it. Any assistance would be greatly appreciated.
Thanks,
DK