import arcpy import numpy import random VCtif = "D:\\Maggie Data\\VCF Time Series Data\\Trial\\phase2\\TC_2010.h21v02.tif" VC = arcpy.RasterToNumPyArray(VCtif) # VC tif will be 1 of 4 VC tiffs, from loop #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # part a) generate random pixels # create tuples for tree classes c1 = numpy.where((VC >= 0) & (VC <= 10)) # class 1 c2 = numpy.where((VC >= 11) & (VC <= 20)) c3 = numpy.where((VC >= 21) & (VC <= 40)) c4 = numpy.where((VC >= 41) & (VC <= 60)) c5 = numpy.where((VC >= 61) & (VC <= 100)) classlist = [c1, c2, c3, c4, c5] points = [] # empty list to store random points (will be a list of tuples) # loop through c1...c5 and generate 2 random points for each for c in classlist: X = c[0].tolist() # x list Y = c[1].tolist() # y list x1= random.choice(X) # choose random point from class n ind = X.index(x1) # find location of this point y1 = Y[ind] # find corresponding y point points.append((x1, y1)) # add to points list x2= random.choice(X) # do the same for a second point in class n while x2 == x1: x2 = random.choice(X) # keep generating random second point to ensure it is different from x1 ind2 = X.index(x2) y2 = Y[ind2] points.append((x2, y2)) ##for i in range(0,10): ## print VC[points] # ensure that values represent 5 class equally
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.