-1
\$\begingroup\$

I have the following ArcPy code, which I need to run on very large datasets. Are there any suggestions for making it run faster? It's taking upwards of an hour and half to run the section I posted below, and there are 5 such sections within the entire code.

if fhz_chk == "true":
arcpy.analysis.Intersect([FHZ,analysislyr],"FHZ_Int","ALL","","INPUT")
arcpy.analysis.Intersect([FHB,analysislyr],"FHB_Int","ALL","","INPUT")
arcpy.management.CalculateField("FHZ_Int","FHZ", 1)
arcpy.management.CalculateField("FHB_Int","FHB", 1)
arcpy.management.Merge(["FHZ_Int","FHB_Int"],fhz_class)
arcpy.management.CalculateField(
    fhz_class,
    "FHZ_Sev",
    "iif($feature.FHZ == '1', 'Severe', iif($feature.FHB == '1', 'High','None'))",
    "ARCADE"
)
arcpy.management.CalculateField(
    fhz_class, 
    "FHZ_Sev_Number",
    f"iif($feature.FHZ_Sev == 'Severe', {fhz_sev_val}, "
    f"iif($feature.FHZ_Sev == 'High', {fhz_high_val}, "
    f"iif($feature.FHZ_Sev == 'Moderate', {fhz_mod_val}, {fhz_low_val})))",
    "ARCADE"
)
fhzflds = arcpy.ListFields(fhz_class)
for field in fhzflds:
    if field.name == "Priority":
        arcpy.AddMessage("Priority set by rdwy")
    else:
        arcpy.management.CalculateField(fhz_class,"Priority",f"{priority_value}","ARCADE")
arcpy.management.CalculateField(
    in_table=fhz_class,
    field = f"FHZ_Impact_{analysislyr}",
    expression = "safe_float(!FHZ_Sev_Number!) * safe_float(!Priority!)",
    expression_type = "PYTHON3",
    code_block = """

def safe_float(val):
return float(val) if val is not None else 0
""",
    field_type = "DOUBLE"
)
FHZ_Impact_Total = f"FHZ_Impact_{analysislyr}"
else:
  arcpy.AddMessage("FHZ not analyzed as a hazard")
  FHZ_Impact_Total = 0

The run time isn't horrid on smaller datasets, but its unusable on the larger ones I need to perform the analysis on.

New contributor
bskaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
2
  • \$\begingroup\$ The cPython 3.14 interpreter fails to parse the OP code, with IndentationError. And that's not the only difficulty with its syntax. // You omitted essential import statements. We don't know what FHZ, analysislyr, and a bunch of other symbols describe. It's unclear what business Use Case you seek to address, and how this code might accomplish that. We are told that elapsed time exceeds 5400 seconds, but we're ignorant of the nature of the input records nor how many were offered. Please take the tour. \$\endgroup\$ Commented Nov 26 at 4:56
  • \$\begingroup\$ Welcome! The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state the task accomplished by the code. Please see How to Ask for examples, and revise the title accordingly. \$\endgroup\$ Commented Nov 26 at 10:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.