2

I am struggling with running a simple piece of code using Python in ArcGIS field calculator. I suspect it could be a very simple error and need an extra set of eyes.

For summer months (Dec-Feb) and winter months (Jun-Aug) I would like to check for specific minimum and maximum values in my data and assign them a comment if the query is met. The code that I have written is given below, however, when running the code I get a syntax parsing error.

def Reclass (tmeanJAN,tmeanFEB,tmeanDEC,tmeanJUN,tmeanJUL,tmeanAUG):
 if tmeanJAN and tmeanFEB and tmeanDEC = 28:
 return "Ideal maximum summer temperature"
 elif tmeanJAN and tmeanFEB and tmeanDEC = 18:
 return "Ideal minimum summer temperature"
 elif tmeanJUN and tmeanJUL and tmeanAUG = 23:
 return "Ideal maximum winter temperature"
 elif tmeanJUN and tmeanJUL and tmeanAUG = 8:
 return "Ideal minimum winter temperature"
 else:
 return "N/A"

Called with:

Reclass(!Int_tmeanJAN!, !Int_tmeanFEB!, !Int_tmeanDEC!, !Int_tmeanJUN!, !Int_tmeanJUL!, !Int_tmeanAUG!)

A sample of my dataset is provided in the screenshot: enter image description here

Bera
81.6k14 gold badges84 silver badges197 bronze badges
asked Sep 22, 2021 at 8:35
0

1 Answer 1

4

= should be ==

= is for assigning a value to a variable, for example a=10

== is for comparing, 10==10 will be True

But your function wont work as intended:

a = 1
b = 2
c = 1
print a and c and b == 1
False

But:

print a and b and c == 1
True

b isnt 1, but it says True. You are asking are a not null and b not null and c 1, and that is True.

Try this instead:

def Reclass (tmeanJAN,tmeanFEB,tmeanDEC,tmeanJUN,tmeanJUL,tmeanAUG):
 if all(temp==28 for temp in [tmeanJAN, tmeanFEB, tmeanDEC]):
 return "Ideal maximum summer temperature"
 elif all(temp==18 for temp in [tmeanJAN, tmeanFEB, tmeanDEC]):
 return "Ideal minimum summer temperature"
 elif all(temp==23 for temp in [tmeanJUN, tmeanJUL, tmeanAUG]):
 return "Ideal maximum winter temperature"
 elif all(temp==8 for temp in [tmeanJUN, tmeanJUL, tmeanAUG]):
 return "Ideal minimum winter temperature"
 else:
 return "N/A"
answered Sep 22, 2021 at 8:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.