Tableview to Tableview temporary join. Here is the code below in the offending function. I tried playing around with table names in field references to try to get it to work, but to no avail. The script does not even step into the cursor, fails hard on {rows = arcpy.UpdateCursor(calc_table)} line.
def pieces():
""" Calculates CON_PIECE, DEC_PIECE, CON_VOL and DEC_VOL fields """
""" ~3.5 hours total, ~3 hours for join """
vol_tab = "strata_volumes"
joinField = "STRATA"
arcpy.AddIndex_management(calc_table, "STRATA", "STRA_IND")
strata_table = arcpy.MakeTableView_management(vol_tab)
print "Starting join at "+datetime.datetime.now().strftime("%H:%M:%S")
#Syntax
#AddJoin_management (in_layer_or_view, in_field, join_table, join_field, {join_type})
arcpy.AddJoin_management(calc_table, joinField, strata_table, joinField)
#arcpy.JoinField_management(calc_table, joinField, vol_tab, joinField)
print "Done join at "+datetime.datetime.now().strftime("%H:%M:%S")
#decid_list = ["Aw","Pb","Bw"]
#con_list = ["Sw", "Sb", "Fb", "Pl", "Pj", "Lt"]
species = [
("C","Fb","FB_STEMS"),("C","Sw","SW_STEMS"),("C","Pj","PJ_STEMS"), # 0,1,2
("C","Pl","PJ_STEMS"),("C","Lt","LT_STEMS"),("C","Sb","SB_STEMS"), # 3,4,5
("D","Bw","BW_STEMS"),("D","Aw","AW_STEMS"),("D","Pb","PB_STEMS") # 6,7,8
]
sp_fields = [("SP1","SP1_PER"),("SP2","SP2_PER"),("SP3","SP3_PER"),
("SP4","SP4_PER"),("SP5","SP5_PER")]
rows = arcpy.UpdateCursor(calc_table)
spec_count = 0
sp_count = 0
row_count = 0
for row in rows:
con = float(0)
dec = float(0)
dec_p = float(row.getValue("avi_copy.DEC_PER"))
for sp in sp_fields:
sp_type = row.getValue("avi_copy."+sp[0])
spp_f = float(row.getValue("avi_copy."+sp[1]))
if spp_f > 0:
for spec in species:
stem_f = row.getValue(strata_table+"."+spec[2])
if spec[0] == "C" and dec_p < 10.0 and sp_type == spec[1]:
con = con + (spp_f * stem_f) / (10 - dec_p)
elif spec[0] == "D" and dec_p > 0.0 and sp_type == spec[1]:
dec = dec + (spp_f * stem_f) / dec_p
else:
continue
else:
continue
vol_ha = row.getValue(strata_table+".VOL_HA")
con_vol = 0
dec_vol = 0
if dec_p == 10:
con_vol = vol_ha * 0.03
dec_vol = vol_ha - con_vol
elif dec_p == 0:
dec_vol = vol_ha * 0.03
con_vol = vol_ha - dec_vol
elif dec_p > 0 and dec_p < 10:
dec_vol = vol_ha * (dec_p / 10)
con_vol = vol_ha - dec_vol
row.avi_copy.con_volha = con_vol
row.avi_copy.dec_volha = dec_vol
row.avi_copy.con_piece = con
row.avi_copy.dec_piece = dec
rows.updateRow(row)