text: # -*- coding: utf-8 -*-
  """
  Generated by ArcGIS ModelBuilder on : 2020-07-30 16:59:54
  """
  import arcpy
  
  def SVI():  # SVI and Finish
  
      # To allow overwriting outputs change overwriteOutput option to True.
      arcpy.env.overwriteOutput = False
  
      fishnet_clip_mod2 = "D:\\SRCFloodVulnerability\\SRCFloodVulnerability.gdb\\fishnet_clip_mod2"
      fishnet_clip = "D:\\SRCFloodVulnerability\\SRCFloodVulnerability.gdb\\fishnet_clip"
      svi = "D:\\SRCFloodVulnerability\\SRCFloodVulnerability.gdb\\svi"
      SRCFloodVulnerability_gdb = "D:\\SRCFloodVulnerability\\SRCFloodVulnerability.gdb"
  
      # Process: Tabulate Intersection (Tabulate Intersection) 
      svi_fn_intersect = "D:\\SRCFloodVulnerability\\SRCFloodVulnerability.gdb\\svi_fn_intersect"
      arcpy.TabulateIntersection_analysis(in_zone_features=fishnet_clip, zone_fields=["OBJECTID"], in_class_features=svi, out_table=svi_fn_intersect, class_fields=["RPL_THEME1"], sum_fields=[], xy_tolerance="", out_units="UNKNOWN")
  
      # Process: Add Field (Add Field) 
      svi_fn_intersect_2_ = arcpy.AddField_management(in_table=svi_fn_intersect, field_name="svi_wgt", field_type="SHORT", field_precision=None, field_scale=None, field_length=None, field_alias="svi_wgt", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")[0]
  
      # Process: Calculate Field (Calculate Field) 
      svi_fn_intersect_3_ = arcpy.CalculateField_management(in_table=svi_fn_intersect_2_, field="svi_wgt", expression="calc_wgts(!PERCENTAGE!)", expression_type="PYTHON3", code_block="def calc_wgts (pct):
      rank_val = 0
      if (pct < 20): 
              rank_val = 1
      if (pct > 20) & (pct < 40): 
              rank_val = 2
      if (pct > 40) & (pct < 60): 
              rank_val = 3
      if (pct > 60) & (pct < 80): 
              rank_val = 4
      if (pct > 80): 
              rank_val = 5
      return rank_val", field_type="TEXT")[0]
  
      # Process: Add Join (Add Join) 
      fishnet_clip_mod2_Layer = arcpy.AddJoin_management(in_layer_or_view=fishnet_clip_mod2, in_field="OBJECTID", join_table=svi_fn_intersect_3_, join_field="OBJECTID_1", join_type="KEEP_ALL")[0]
  
      # Process: Feature Class to Feature Class (Feature Class to Feature Class) 
      fishnet_clip_mod3 = arcpy.FeatureClassToFeatureClass_conversion(in_features=fishnet_clip_mod2_Layer, out_path=SRCFloodVulnerability_gdb, out_name="fishnet_clip_mod3", where_clause="", field_mapping="IN_FID \"IN_FID\" true true false 4 Long 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.IN_FID,-1,-1;FREQUENCY \"FREQUENCY\" true true false 4 Long 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.FREQUENCY,-1,-1;SUM_IN_FID \"SUM_IN_FID\" true true false 8 Double 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.SUM_IN_FID,-1,-1;rls_wgt \"rls_wgt\" true true false 2 Short 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.rls_wgt,-1,-1;OBJECTID \"OBJECTID\" true true false 4 Long 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.OBJECTID,-1,-1;OBJECTID_1 \"OID\" true true false 4 Long 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.OBJECTID_1,-1,-1;bfe_bool \"bfe_bool\" true true false 2 Short 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.bfe_bool,-1,-1;bfe_bool_1 \"bfe_bool\" true true false 2 Short 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.bfe_bool_1,-1,-1;AREA \"AREA\" true true false 8 Double 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.AREA,-1,-1;PERCENTAGE \"PERCENTAGE\" true true false 8 Double 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.PERCENTAGE,-1,-1;bfe_wgt \"bfe_wgt\" true true false 2 Short 0 0,First,#,fishnet_clip_mod2_Layer,fishnet_clip_mod2.bfe_wgt,-1,-1;OBJECTID_12 \"OID\" true true false 4 Long 0 0,First,#,fishnet_clip_mod2_Layer,svi_fn_intersect.OBJECTID_1,-1,-1;RPL_THEME1 \"RPL_THEME1\" true true false 8 Double 0 0,First,#,fishnet_clip_mod2_Layer,svi_fn_intersect.RPL_THEME1,-1,-1;AREA_1 \"AREA\" true true false 8 Double 0 0,First,#,fishnet_clip_mod2_Layer,svi_fn_intersect.AREA,-1,-1;PERCENTAGE_1 \"PERCENTAGE\" true true false 8 Double 0 0,First,#,fishnet_clip_mod2_Layer,svi_fn_intersect.PERCENTAGE,-1,-1;svi_wgt \"svi_wgt\" true true false 2 Short 0 0,First,#,fishnet_clip_mod2_Layer,svi_fn_intersect.svi_wgt,-1,-1", config_keyword="")[0]
  
      # Process: Calculate Field (2) (Calculate Field) 
      fishnet_clip_mod2_2_ = arcpy.CalculateField_management(in_table=fishnet_clip_mod3, field="svi_wgt", expression="zero_out(!bfe_wgt!)", expression_type="PYTHON3", code_block="def zero_out(flswgt):
      if flswgt is not None:
          return flswgt
      else:
          return 0", field_type="TEXT")[0]
  
      # Process: Add Field (4) (Add Field) 
      fishnet_clip_mod3_2_ = arcpy.AddField_management(in_table=fishnet_clip_mod2_2_, field_name="mod_wgt", field_type="FLOAT", field_precision=2, field_scale=None, field_length=None, field_alias="mod_wgt", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")[0]
  
      # Process: Calculate Field (4) (Calculate Field) 
      fishnet_clip_mod3_4_ = arcpy.CalculateField_management(in_table=fishnet_clip_mod3_2_, field="mod_wgt", expression="(!bfe_wgt! + !svi_wgt! + !rls_wgt!)/3", expression_type="PYTHON3", code_block="", field_type="TEXT")[0]
  
  if __name__ == '__main__':
      # Global Environment settings
      with arcpy.EnvManager(scratchWorkspace=r"D:\SRCFloodVulnerability\SRCFloodVulnerability2.gdb", workspace=r"D:\SRCFloodVulnerability\SRCFloodVulnerability2.gdb"):
          SVI()
  