def output_results(): """ This function writes results to the output feature class. """ HF.pGP.AddMessage("--------" + getCurTime() + "--------") HF.pGP.AddMessage("Outputting results...") outField = "SpCluster" # Add results field. if not properties.dcFields.has_key(outField.upper()): try: HF.pGP.AddField(inputs.sOutputFC, outField, "text") except: HF.pGP.GetMessages(2) else: outField = "SpCluster_1" if not properties.dcFields.has_key(outField.upper()): try: HF.pGP.AddField(inputs.sOutputFC, outField, "text") except: HF.pGP.GetMessages(2) # Add results to output FC HF.pGP.AddMessage(HF.sWritingResults) # sFieldList = properties.sFID + ";" + sField + ";" + cField pRows = HF.pGP.UpdateCursor(inputs.sOutputFC) pRow = pRows.Next() # add message of processes iError = 0 iCnt = 0 fInterval = len(attri) / 5.0 fMore = fInterval iComplete = 20 iKey = 0 # test = [] while pRow <> None: iKey = pRow.GetValue("FID") # print iKey try: pRow.SetValue(outField, clusterAttri[iKey, -1]) pRows.UpdateRow(pRow) iCnt = iCnt + 1 if iCnt > fInterval: fInterval, iComplete = HF.check_progress(fInterval, fMore, iComplete) # except: pass except: iError = iError + 1 pRow = pRows.Next() # print "++++++++++++++++++++++" # print iError HF.pGP.AddMessage(HF.s100Percent) HF.pGP.AddMessage(" ") pRows = None
def output_results(mDict,cDict): """ This function writes results to the output feature class. """ sField = "MaxGi" cField = "Core" # Add results field. if not properties.dcFields.has_key(sField.upper()): HF.pGP.AddField(inputs.sOutputFC, sField, "FLOAT") if not properties.dcFields.has_key(cField.upper()): HF.pGP.AddField(inputs.sOutputFC, cField, "TEXT") # Add results to output FC HF.pGP.AddMessage (HF.sWritingResults) sFieldList = properties.sFID + ";" + sField + ";" + cField pRows = HF.pGP.UpdateCursor(inputs.sOutputFC,"","",sFieldList) #pRows = pGP.UpdateCursor(inputs.sOutputFC) pRow = pRows.Next() iCnt = 0 fInterval = len(keys) / 5.0 fMore = fInterval iComplete = 20 while pRow <> None: iKey = pRow.GetValue(properties.sFID) try: if mDict [iKey]: # make sure we have a non-Null result. pRow.SetValue(sField, mDict[iKey]) pRows.UpdateRow(pRow) iCnt = iCnt + 1 if iCnt > fInterval: fInterval, iComplete = HF.check_progress(fInterval, fMore, iComplete) except: pass try: if cDict [iKey]: # make sure we have a non-Null result. pRow.SetValue(cField, cDict[iKey]) pRows.UpdateRow(pRow) except: pRow.SetValue(cField, "Outside Clusters") pRows.UpdateRow(pRow) pRow = pRows.Next() HF.pGP.AddMessage (HF.s100Percent) HF.pGP.AddMessage(" ") pRows = None return sField
def output_results(Cluster): """ This function writes results to the output feature class. """ # Add results field. HF.pGP.AddMessage ("--------" + getCurTime() + "--------") HF.pGP.AddMessage ("Adding results fields...") addField = [] for Field in inputs.sZField: if len(Field) > 8: Field = Field[0:8] #Field = Field + "_N" addField.append(Field + "_N") if inputs.sXY == "Yes": addField.append("X_cent_N") addField.append("Y_cent_N") for Field in addField: if not properties.dcFields.has_key(Field.upper()): HF.pGP.AddField(inputs.sOutputFC, Field, "FLOAT") outField = "CLUSTER" if not properties.dcFields.has_key(outField.upper()): HF.pGP.AddField(inputs.sOutputFC, outField, "LONG") else: outField = "CLUSTER_1" if not properties.dcFields.has_key(outField.upper()): HF.pGP.AddField(inputs.sOutputFC, outField, "LONG") #addField.append("CLUSTER") # Add results to output FC HF.pGP.AddMessage ("--------" + getCurTime() + "--------") HF.pGP.AddMessage (HF.sWritingResults) pRows = HF.pGP.UpdateCursor(inputs.sOutputFC) pRow = pRows.Next() iError = 0 iCnt = 0 fInterval = len(attri) / 5.0 fMore = fInterval iComplete = 20 while pRow <> None: iKey = pRow.GetValue("FID") #print iKey try: if Cluster[iKey]: # make sure we have a non-Null result. #since the type of Cluster[iKey] is numpy.int32, it should convert to [int] for Field in addField: iIndex = addField.index(Field) temp = float(clusterAttri_Norm[iKey, iIndex]) pRow.SetValue(Field, temp) temp = int(Cluster[iKey]) pRow.SetValue(outField, temp) pRows.UpdateRow(pRow) iCnt = iCnt + 1 if iCnt > fInterval: fInterval, iComplete = HF.check_progress(fInterval, fMore, iComplete) #except: pass except: iError = iError + 1 pRow = pRows.Next() #print "++++++++++++++++++++++" print iError HF.pGP.AddMessage (HF.s100Percent) HF.pGP.AddMessage(" ") pRows = None
if aStat > 0: clusterHighList.append([aList,aStat]) else: clusterLowList.append([aList,aStat]) for j in aList: if maxDict.has_key(j): if abs(aStat) > abs(maxDict[j]): maxDict[j] = aStat else: maxDict[j] = aStat iCnt += 1 if iCnt > fInterval: fInterval, iComplete = HF.check_progress(fInterval, fMore, iComplete) if method=="2": HF.pGP.AddWarning("Finding FDR...") data={} data=maxDict.copy() for j in range(0,iNumRecs): #print data[j], data[j]=[pValForGi(data[j]),data[j]] #print data[j][0] alpha=float(inputs.confidenceLevel) for j in range(0,iNumRecs-1): for i in range(0,iNumRecs-1): if data[i][0] < data[i+1][0]: tem=data[i] data[i]=data[i+1]
def output_results(deviation): """ This function writes results to the output feature class. """ HF.pGP.AddMessage ("--------" + getCurTime() + "--------") HF.pGP.AddMessage ("Outputting results...") outField = "Outlier" # Add results field. if not properties.dcFields.has_key(outField.upper()): try: HF.pGP.AddField(inputs.sOutputFC, outField, "TEXT") except: HF.pGP.GetMessages(2) else: outField = "Outlier_1" if not properties.dcFields.has_key(outField.upper()): try: HF.pGP.AddField(inputs.sOutputFC, outField, "TEXT") except: HF.pGP.GetMessages(2) addField = [] for Field in inputs.sZField: if len(Field) > 8: Field = Field[0:8] #Field = Field + "_N" addField.append(Field + "_O") for Field in addField: if not properties.dcFields.has_key(Field.upper()): HF.pGP.AddField(inputs.sOutputFC, Field, "TEXT") # Add results to output FC HF.pGP.AddMessage (HF.sWritingResults) #sFieldList = properties.sFID + ";" + sField + ";" + cField pRows = HF.pGP.UpdateCursor(inputs.sOutputFC) pRow = pRows.Next() # add message of processes iError = 0 iCnt = 0 fInterval = len(attri) / 5.0 fMore = fInterval iComplete = 20 iKey = 0 #test = [] while pRow <> None: #iKey = pRow.GetValue("FID") #print iKey try: if deviation[iKey] > fRange: # make sure we have a non-Null result. pRow.SetValue(outField, "Y") for Field in addField: iIndex = addField.index(Field) #print iIndex #print clusterAttri[iKey,0:-1], average[iIndex,0:-1] #test.append(calculate_single_deviation(clusterAttri[iKey,0:-1], average, iIndex)) if calculate_single_deviation(clusterAttri[iKey,:], average, iIndex): pRow.SetValue(Field, "Y") else: pRow.SetValue(Field, "N") #pRow.SetValue(Field, temp) else: pRow.SetValue(outField, "N") for Field in addField: pRow.SetValue(Field, "N") pRows.UpdateRow(pRow) iCnt = iCnt + 1 if iCnt > fInterval: fInterval, iComplete = HF.check_progress(fInterval, fMore, iComplete) #pRow = pRows.Next() #except: pass except: iError = iError + 1 pRow = pRows.Next() iKey = iKey + 1 #print "++++++++++++++++++++++" #print iError HF.pGP.AddMessage (HF.s100Percent) HF.pGP.AddMessage(" ") pRows = None