AnsweredAssumed Answered

Use Python to Reclass a Field Based on Multiple Input Fields

Question asked by Ecologist_Guy on Aug 2, 2018
Latest reply on Aug 6, 2018 by Ecologist_Guy

Hi everybody,

 

I have a field called 'Status' that I reclassify every evening so I can update our symbology on one of my web maps. I wrote a function in Arcade that works, but in the interest of automation I am trying to convert my scripts to Python so I can use them in model builder.

 

There are 9 fields that contribute to the calculation of the field status. They are:

Date_Found

MIN_Hatchling_Emergence_Date

Data_Type

Washout

Removed

Need_to_Check

Assigned_HS

SOH_yes_no

Treatment_Code!

 

 

I am trying to use the Calculate Field Tool. When I click verify it says the expression is valid. The code will run but it returns <null>  in the status filed for every feature. I'm not too familiar with Python. Does anybody have any suggestions? I found a few examples online, but they all reclasses based on one input feature.

 

I enter this in the expression box:

reclass(!Date_Found!,!MIN_Hatchling_Emergence_Date!,!Data_Type!,!Washout!,!Removed!,!Need_to_Check!,!Assigned_HS!,!SOH_yes_no!,!Treatment_Code!)

 

And this in the Code Block Box:

def reclass(Date_Found,Date_SOH,Nest_or_Crawl,Washout,Removed,Check,Assigned_HS,SOH,TTT):

    if Nest_or_Crawl == "Crawl":

        if (time.strftime("%d/%m/%Y"))-Date_Found>=7:

            return "Old Crawl"

        else:

            return "Recent Crawl"

    elif Washout=="Y":

        return "Washed Out"

    elif Removed=="Y":

        return "Removed"

    elif Check =="Y":

        return "Check"

    elif (Assigned_HS=="N" and

         (time.strftime("%d/%m/%Y"))-Date_Found>=70):

             return "Ready for Removal"

    elif (Assigned_HS=="N" and

         SOH=="Y" and  (time.strftime("%d/%m/%Y"))-Date_SOH>=3):

             return "Ready for Removal"

    elif Assigned_HS=="Y" and [(time.strftime("%d/%m/%Y"))-Date_Found>=70 or

         (SOH=="Y" and (time.strftime("%d/%m/%Y"))-Date_SOH>=3)]:

             return "Ready for HS"

    elif Date_Found>=45 or TTT=="9":

        return "Look for SOH"

    else:

        return "Incubating"

 

Thank you for your time.

Outcomes