I was QAQC'g my code results and found unexpected values.
My code queries point and polygon layers looking for how many negative test result are gathered before a positive.
It appears when checking the values for negatives prior to positive that the getCount includes the earliest positive (or it is always one more than expected.
Why? Do I need to physically clear the selection before making the second "New_Selection"
Thanks,
Alicia
My code queries point and polygon layers looking for how many negative test result are gathered before a positive.
Code:
for grid in grids:
dates = []
arcpy.SelectLayerByLocation_management("cwdpts4Anlys", "WITHIN", grid.shape, "", "NEW_SELECTION")
positives = arcpy.SearchCursor("cwdpts4Anlys",' "PRION_DETECTED" = 1 ' , "", "SAMPLEDATE" )
for positive in positives:
dates.append(positive.SAMPLEDATE)
earliest = min(dates)
grid.setValue("FrstPosDte", earliest)
posYear = earliest.year
print posYear
negDates = []
arcpy.SelectLayerByLocation_management("cwdpts4Anlys", "WITHIN", grid.shape,"", "NEW_SELECTION")
negatives = arcpy.SearchCursor("cwdpts4Anlys",' "PRION_DETECTED" = 0 ', "", "SAMPLEDATE")
for negative in negatives:
negDates.append(negative.SAMPLEDATE)
if negDates:
earliestNeg = min(negDates)
print earliestNeg
grid.setValue("FrstNegDte", earliestNeg)
where = "EXTRACT(YEAR from {0}) <= {1}".format(arcpy.AddFieldDelimiters("cwdpts4Anlys", "SAMPLEDATE"), posYear)
arcpy.SelectLayerByAttribute_management("cwdpts4Anlys", "SUBSET_SELECTION", where)
result = int(arcpy.GetCount_management("cwdpts4Anlys").getOutput(0))
print result
grid.setValue("NgPriorPs", result)
else:
grid.setValue("NgPriorPs", 0)
grids.updateRow(grid)
Why? Do I need to physically clear the selection before making the second "New_Selection"
Thanks,
Alicia