-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontours.py
executable file
·619 lines (599 loc) · 20.5 KB
/
contours.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
from Scientific.Geometry import *
from math import *
import string
#from matplotlib import *
from pylab import *
import copy
def sortXYtuples(data, sortIndex1, sortIndex2, S1):
# note: this was a fun exercise before finding the map(operator.itemgetter()) built in way to sort
# d>1 tuples. that said, can we use this pseudo-built-in method to sort on two indeces? i think you can do this
# by creating a function to sort on (aka, create an index S[i][x].S[i][y], where a.b indicates some sort of integer
# digit transformation so that 1,1 -> 11, 1,2, -> 12, 2,3-> 23, etc. (here, x_max=10).
#
# data is clearly your data - nested lists/tuples, whatever.
# sortIndex1,2 is the index on which to sort (aka, ix, iy)
# S1,2 are the dimensions of the system. aka, an x then y sort
# on a 100, 200 grid.
#
# strategy: transform x,y into a 1D index: x,y -> y*X + x
#
dd = {}
retuple = []
#
for rows in data:
thisIndex = rows[sortIndex1]*S1+rows[sortIndex2]
dd[thisIndex] = rows
#
listIndex = list(dd.keys())
listIndex.sort()
#x
for myindex in listIndex:
retuple = retuple + [dd[myindex]]
#similarly, i think, though there is some proving to be done, that if we subtract a - scrambled(a),
return retuple
def getDataTuplesFromFile(filename, delim=None):
myfile = open(filename, 'r')
outdata = []
for lines in myfile:
if lines[0]=='#': continue
#
if delim==None:
# guess a delimiter (obviously, this is not a sophisticated guess):
delim=' '
if '\t' in lines: delim='\t'
#
linestuple = lines.split(delim)
for i in range(len(linestuple)):
linestuple[i] = float(linestuple[i])
#linestuple[2] = linestuple[2][:-2]
outdata = outdata + [linestuple]
#
return outdata
def boxyContour2(data, z0=0, ix=0, iy=1, iz=2, dx=.1, dy=.1):
# so i think this basically takes a bunch of contiguous boxes and makes a single polygon, which facilitates much more compact KML.
# it might start with just the box center data points.
# get max x,y values:
maxX = 0
maxY = 0
for rows in data:
#print rows
if rows[ix]>maxX:
maxX = rows[ix]
if rows[iy]>maxY:
maxY = rows[iy]
#print maxX
#print maxY
# first, sort y, then x (scan in x):
data1 = sortXYtuples(data, iy, ix, maxX)
# scan the sorted data. when we get a state change (aka, step onto or off of a z0 site), set a point.
cdata = [] # contour data set
dstate = 0
lastPos = [data1[0][ix]-dx, data1[0][iy]]
for rows in data1:
# and rows[ix]=lastx+dx and rows[iy]=lasty
# new region:
if rows[iz]>=z0 and dstate==0:
# we've hit a new "high" spot
dstate=1
if [rows[ix], rows[iy]] not in cdata:
#cdata = cdata + [rows[ix], rows[iy], rows[iz]]
cdata = cdata + [[rows[ix], rows[iy]]]
elif (dstate==1 and rows[iz]<z0):
# we fall off the contour onto a data element
dstate=0
if lastPos not in cdata:
# but we want to keep the previous element in the contour set...
cdata = cdata + [lastPos]
elif (dstate==1 and rows[iz]>=z0 and rows[ix]!=lastPos[0]+dx or rows[iy]!=lastPos[1] ):
# we're on a contour and skip over some empty data elements onto a new contour.
if lastPos not in cdata:
cdata = cdata + [lastPos]
if [rows[ix], rows[iy]] not in cdata:
cdata = cdata + [[rows[ix], rows[iy]]]
#
lastPos = [rows[ix], rows[iy]]
#
# now, sort by x then y, repeat with vertical scan, add to cdata:
data1 = sortXYtuples(data, ix, iy, maxY)
dstate = 0
lastPos = [data1[0][ix], data1[0][iy]-dy]
# scan the sorted data. when we get a state change (aka, step onto or off of a z0 site), set a point.
for rows in data1:
# and rows[ix]=lastx+dx and rows[iy]=lasty
# new region:
if rows[iz]>=z0 and dstate==0:
# we've hit a new "high" spot
dstate=1
if [rows[ix], rows[iy]] not in cdata:
#cdata = cdata + [rows[ix], rows[iy], rows[iz]]
cdata = cdata + [[rows[ix], rows[iy]]]
# we fall off the contour onto a data element
elif (dstate==1 and rows[iz]<z0):
dstate=0
if lastPos not in cdata:
cdata = cdata + [lastPos]
# we're on a contour and skip over some empty data elements onto a new contour.
elif (dstate==1 and rows[iz]>=z0 and rows[iy]!=lastPos[1]+dy or rows[ix]!=lastPos[0] ):
if lastPos not in cdata:
cdata = cdata + [lastPos]
if [rows[ix], rows[iy]] not in cdata:
cdata = cdata + [[rows[ix], rows[iy]]]
#
#
# now we have a contour set. we need to connect these to make a polygon.
# the way we've done this, lines can connect to nn or nnn lattice sites.
# start with a random point in cdata (maybe the first point?).
# it does not matter which direction we go; we just can't backtrack.
# --> this basic method, but instead employing an index (ie, the xy index)
# would probably be faster. the yx scan should probably calculate and use
# the xy index as well...
#
#just in case (this might take a long time, so should maybe be skipped)
#print "starting set"
#cdata = set(cdata)
#print "finishing set"
#
return cdata
def findInTuples(mytuple, theData, startIndex=0):
# returns the index of the found data.
tLen = len(mytuple)
retVal=-1
rowth=0
for rows in theData:
isIn=[]
for i in range(tLen):
if mytuple[i]!=rows[i+startIndex]:
# at least one pair of elements are not equal
isIn=isIn+[False]
break
else:
isIn=isIn+[True] # this is actually unnecessary, but intuitive and instructional... an i guess it protects against empty tuples?
# we've spun through a tuple. is it a hit?
# if isIn contains no "false" entries, the (left nTuples of) theData record match mytuple
if False not in isIn and True in isIn:
# we've found a row that equals our tuple.
retVal=rowth
break
#
#
rowth = rowth+1
#
#
return retVal
def findHeadTailInTuples(mytuple, theData):
# returns the index of the found data.
# let's customize this. we'll always use the first 4 of the tuples.
#tLen = len(mytuple) # this should always be 4...
retVal=-1
rowth=0
headTail=-1
#
for rows in theData:
#print 'from findHeadTail: ' + str(mytuple) + " :: " + str(rows)
if [mytuple[2], mytuple[3]] == [rows[0], rows[1]]:
# head-to-tail
retVal = rowth
headTail=0
break
#
if [mytuple[2], mytuple[3]] == [rows[2], rows[3]]:
# head-to-head
retVal = rowth
headTail=1
break
#
rowth = rowth+1
#
return [headTail, retVal]
def simpleContour2(data, z0=0, ix=0, iy=1, iz=2, dx=.1, dy=.1):
# get max x,y values:
maxX = 0
maxY = 0
# for rows in data:
# #print rows
# if rows[ix]>maxX:
# maxX = rows[ix]
# if rows[iy]>maxY:
# maxY = rows[iy]
# we need to make a copy of just the x,y parts of the data:
d2file = open('data/data2.dat', 'w')
data2=[]
for rows in data:
if abs(rows[iz])>=z0:
#print rows[iz]
data2 = data2 + [[int(round(rows[ix]/dx)), int(round(rows[iy]/dy))]]
d2file.write(str(int(round(rows[ix]/dx))) + '\t' + str(int(round(rows[iy]/dy))) + '\n')
d2file.close()
#
# now, hollow out data2 (in place? be careful of in place; index handling gets messy.)
cdata = []
for rows in data2:
if [rows[ix]+1, rows[iy]] not in data2 or [rows[ix]-1, rows[iy]] not in data2 or [rows[ix], rows[iy]+1] not in data2 or [rows[ix], rows[iy]-1] not in data2 :
print(str([rows[ix], rows[iy]]) + ' :: ' + str([rows[ix]-1, rows[iy]]))
if not [[rows[ix], rows[iy]]] in cdata:
cdata = cdata + [[rows[ix], rows[iy]]]
# if findInTuples([rows[ix]+1, rows[iy]], data2)<0 or findInTuples([rows[ix]-1, rows[iy]], data2)<0:
# print str([rows[ix], rows[iy]]) + ' :: ' + str([rows[ix]+1, rows[iy]])
# if not [[rows[ix], rows[iy]]] in cdata:
# cdata = cdata + [[rows[ix], rows[iy]]]
#
return cdata
def boxyContour(data, z0=0, ix=0, iy=1, iz=2, dx=.1, dy=.1):
# get max x,y values:
maxX = 0
maxY = 0
minX = 9999999999
minY = 9999999999
for rows in data:
#print rows
if rows[ix]>=maxX:
maxX = rows[ix]
if rows[iy]>=maxY:
maxY = rows[iy]
if rows[ix]<=minX:
minX = rows[ix]
if rows[iy]<=minY:
minY = rows[iy]
# we need to make a copy of just the x,y parts of the data:
d2file = open('data/data2.dat', 'w')
data2=[]
for rows in data:
#if abs(rows[iz])>=z0:
if rows[iz]>=z0:
#print rows[iz]
# subtract bias (starting position). this might not be QUITE right, as it starts the binning (if there is binning)
# from the lowest value. it may be necessary to specify minY, minX.
rows[ix] = rows[ix]-minX
rows[iy] = rows[iy]-minY
data2 = data2 + [[int(round(rows[ix]/dx)), int(round(rows[iy]/dy))]]
d2file.write(str(int(round(rows[ix]/dx))) + '\t' + str(int(round(rows[iy]/dy))) + '\n')
#d2file.write(str([[int(round(rows[ix]/dx)), int(round(rows[iy]/dy))]]) + '\n')
d2file.close()
data=None
#
# note: data2 values are in terms of integer-dx,dy values
#
# now, hollow out data2 (in place? be careful of in place; index handling gets messy.)
#cdata = []
rightsies = []
leftsies = []
topsies = []
bottomsies = []
fcont = open('data/contpoints.dat', 'w')
for rows in data2:
if [rows[ix]+1, rows[iy]] not in data2 or [rows[ix]-1, rows[iy]] not in data2 or [rows[ix], rows[iy]+1] not in data2 or [rows[ix], rows[iy]-1] not in data2 :
fcont.write(str(rows[0]) + '\t' + str(rows[1]) + '\n')
if [rows[ix]+1, rows[iy]] not in data2:
# no right neighbor:
rightsies.append(rows)
#cdata = cdata + [[rows[ix]+.5, rows[iy]]]
if [rows[ix]-1, rows[iy]] not in data2:
# no left neighbor:
leftsies.append(rows)
#cdata = cdata + [[rows[ix]-.5, rows[iy]]]
if [rows[ix], rows[iy]+1] not in data2:
topsies.append(rows)
#cdata = cdata + [[rows[ix], rows[iy]+.5]]
if [rows[ix], rows[iy]-1] not in data2 :
bottomsies.append(rows)
#cdata = cdata + [[rows[ix]+.5, rows[iy]-.5]]
#
#if not [[rows[ix], rows[iy]]] in cdata:
# cdata = cdata + [[rows[ix], rows[iy]]]
#
# now, compact these to longer segments (aka, string together contiguous bits)
#
# sort each:
# by x then y:
# clean up a bit:
data2=None # finished with this array; save some memory for later...
fcont.close()
#print 'rightsies: ' + str(len(rightsies))
#print 'leftsies: ' + str(len(leftsies))
#print 'topsies: ' + str(len(topsies))
#print 'bottomsies: ' + str(len(bottomsies))
#vTail = [rightsies[0][0]+.5, rightsies[0][1]-.5]
#thisHead = [rightsies[0][0]+.5, rightsies[0][1]+.5]
rightSegs = []
rightsies = sortXYtuples(rightsies, 0, 1, maxY)
rightsies.append(rightsies[0]) # this tricks the subsequent code into closing the last vector (note we could alternatively do an
vTail = rightsies[0] # "append" operation after the loop
vHead = vTail
for row in rightsies:
if row[0]==vTail[0] and row[1] in [vHead[1]+1, vHead[1]]: # a vector can be its own head/tail
vHead = row
else:
# rightSegs.append(vTail + vHead)
#print vTail, vHead
rightSegs.append([vTail[0]+.5, vTail[1]-.5, vHead[0]+.5, vHead[1]+.5])
vTail = row
vHead = row
#rightSegs.append([vTail[0]+.5, vTail[1]-.5, vHead[0]+.5, vHead[1]+.5])
#
leftSegs = []
leftsies = sortXYtuples(leftsies,0,1, maxY)
leftsies.append(leftsies[0])
vTail = leftsies[0]
vHead = vTail
for row in leftsies:
if row[0]==vTail[0] and row[1] in [vHead[1]+1, vHead[1]]: # a vector can be its own head/tail
vHead = row
else:
#leftSegs.append(vTail + vHead)
leftSegs.append([vTail[0]-.5, vTail[1]-.5, vHead[0]-.5, vHead[1]+.5])
vTail = row
vHead = row
#leftSegs.append([vTail[0]-.5, vTail[1]-.5, vHead[0]-.5, vHead[1]+.5])
#
topSegs = []
topsies = sortXYtuples(topsies,1,0, maxX)
topsies.append(topsies[0])
vTail = topsies[0]
vHead = vTail
for row in topsies:
if row[1]==vTail[1] and row[0] in [vHead[0]+1, vHead[0]]: # a vector can be its own head/tail
vHead = row
else:
#topSegs.append(vTail + vHead)
topSegs.append([vTail[0]-.5, vTail[1]+.5, vHead[0]+.5, vHead[1]+.5])
vTail = row
vHead = row
#topSegs.append([vTail[0]-.5, vTail[1]+.5, vHead[0]+.5, vHead[1]+.5])
#
bottomSegs = []
bottomsies = sortXYtuples(bottomsies,1,0, maxX)
bottomsies.append(bottomsies[0])
vTail = bottomsies[0]
vHead = vTail
vlen=0
for row in bottomsies:
if row[1]==vTail[1] and row[0] in [vHead[0]+1, vHead[0]]: # a vector can be its own head/tail; we allow 2 conditions to jump-start the process.
vHead = row
else:
# bottomSegs.append(vTail + vHead)
bottomSegs.append([vTail[0]-.5, vTail[1]-.5, vHead[0]+.5, vHead[1]-.5])
vTail = row
vHead = row
#bottomSegs.append([vTail[0]-.5, vTail[1]-.5, vHead[0]+.5, vHead[1]-.5])
#
# clean up a bit:
rightsies = None
leftsies = None
topsies = None
bottomsies = None
#
# and now, we have (4) sets of vectors outlining shapes. we need to arrange them head to tail.
# we use each vector once, so we can "pop()" them out of the stack as we go.
# we could combine these four sets of tuples, then for each row, search the whole stack.
# arguably, we actually save a little bit of time by separating them. we know a LEFT vector
# will not connect to another LEFT or RIGHT vector, so we can skip that stack. create a tuple of polygon-tuples
polygons = []
# these segment vectors are godless and without direction or morality, so we look for a fellow segment
# with an overlapping head OR tail. we select our initial direction arbitrarily to be this vecor's head.
# we loop until we connect to its tail.
#
while len(rightSegs + leftSegs + topSegs + bottomSegs)>0:
#print 'remaining segments: ' + str(len(rightSegs + leftSegs + topSegs + bottomSegs))
# start a new polygon:
thisPoly=[]
# start with any segment:
if len(rightSegs)>0:
thisSeg = rightSegs.pop(0) # remove rightSegs[0] into thisSeg
elif len(leftSegs)>0:
thisSeg = leftSegs.pop(0)
elif len(topSegs)>0:
thisSeg = topSegs.pop(0)
elif len(bottomSegs)>0:
thisSeg = bottomSegs.pop(0)
#
#thisPoly.append(thisSeg)
thisPoly.append([thisSeg[0]*dx + minX, thisSeg[1]*dy + minY])
thisPoly.append([thisSeg[2]*dx + minX, thisSeg[3]*dy + minY])
nextSeg = []
polyTail = [thisSeg[0], thisSeg[1]]
while [thisSeg[2], thisSeg[3]] != polyTail: # note, this breaks for length zero polygons. could do a head & tail condition.
# use only horizontal->vertical for vertical->horizontal vectors:
# there is some clumsy, not super intuitive code here to optimize search time...
# i should probably use the "ctypes" library to make pointers to these arrays
# but i think for now, we'll just write more code.
#
#print thisSeg
if thisSeg[0]==thisSeg[2]:
# horizontal vector; check for vertical next-vector:
segIndex=0
foundOne = findHeadTailInTuples(thisSeg, topSegs)
# we get back a tuple like: [{0 if match tail, 1 if match head}, {index if found, else -1}]
if foundOne[1]==-1:
segIndex=1
foundOne = findHeadTailInTuples(thisSeg, bottomSegs)
elif thisSeg[1]==thisSeg[3]:
# a vertical vector. we should probably throw in an error trap if both fail.
segIndex=2
foundOne = findHeadTailInTuples(thisSeg, leftSegs)
if foundOne[1]==-1:
segIndex=3
foundOne = findHeadTailInTuples(thisSeg, rightSegs)
#print 'foundone' + str(foundOne)
#
if foundOne[1]>=0: # at this point, it better be...
# fetch the segment from the appropriate tuple:
if segIndex==0:
nextSeg=topSegs.pop(foundOne[1])
if segIndex==1:
nextSeg=bottomSegs.pop(foundOne[1])
if segIndex==2:
nextSeg=leftSegs.pop(foundOne[1])
if segIndex==3:
nextSeg=rightSegs.pop(foundOne[1])
#
if foundOne[0]==1:
# we matched head-to-head; switch order.
nextSeg=[nextSeg[2], nextSeg[3], nextSeg[0], nextSeg[1]]
#
# finally, we have the next segment. append to thisPoly:
#thisPoly.append(nextSeg)
thisPoly.append([(nextSeg[2]*dx)+minX, (nextSeg[3]*dy)+minY])
thisSeg=nextSeg
else:
print('failed to find continuing vector.')
thisPoly.append([(polyTail[0]*dx)+minX, (polyTail[1]*dy)+minY])
break
break
#
#
#
polygons.append(thisPoly)
#
# function root level
#
#return rightsies + leftsies + topsies + bottomsies
#return cdata
#
#return rightSegs+leftSegs+topSegs+bottomSegs
#
return polygons
#
# end function
def simpleContour(data, z0=0, ix=0, iy=1, iz=2, dx=.1, dy=.1):
# get max x,y values:
maxX = 0
maxY = 0
for rows in data:
#print rows
if rows[ix]>maxX:
maxX = rows[ix]
if rows[iy]>maxY:
maxY = rows[iy]
#print maxX
#print maxY
# first, sort y, then x (scan in x):
data1 = sortXYtuples(data, iy, ix, maxX)
# scan the sorted data. when we get a state change (aka, step onto or off of a z0 site), set a point.
cdata = [] # contour data set
dstate = 0
lastPos = [data1[0][ix]-dx, data1[0][iy]]
for rows in data1:
# and rows[ix]=lastx+dx and rows[iy]=lasty
# new region:
if rows[iz]>=z0 and dstate==0:
# we've hit a new "high" spot
dstate=1
if [rows[ix], rows[iy]] not in cdata:
#cdata = cdata + [rows[ix], rows[iy], rows[iz]]
cdata = cdata + [[rows[ix], rows[iy]]]
# we fall off the contour onto a data element
elif (dstate==1 and rows[iz]<z0):
dstate=0
if lastPos not in cdata:
cdata = cdata + [lastPos]
# we're on a contour and skip over some empty data elements onto a new contour.
elif (dstate==1 and rows[iz]>=z0 and rows[ix]!=lastPos[0]+dx or rows[iy]!=lastPos[1] ):
if lastPos not in cdata:
cdata = cdata + [lastPos]
if [rows[ix], rows[iy]] not in cdata:
cdata = cdata + [[rows[ix], rows[iy]]]
#
lastPos = [rows[ix], rows[iy]]
#
# now, sort by x then y, repeat with vertical scan, add to cdata:
data1 = sortXYtuples(data, ix, iy, maxY)
dstate = 0
lastPos = [data1[0][ix], data1[0][iy]-dy]
# scan the sorted data. when we get a state change (aka, step onto or off of a z0 site), set a point.
for rows in data1:
# and rows[ix]=lastx+dx and rows[iy]=lasty
# new region:
if rows[iz]>=z0 and dstate==0:
# we've hit a new "high" spot
dstate=1
if [rows[ix], rows[iy]] not in cdata:
#cdata = cdata + [rows[ix], rows[iy], rows[iz]]
cdata = cdata + [[rows[ix], rows[iy]]]
# we fall off the contour onto a data element
elif (dstate==1 and rows[iz]<z0):
dstate=0
if lastPos not in cdata:
cdata = cdata + [lastPos]
# we're on a contour and skip over some empty data elements onto a new contour.
elif (dstate==1 and rows[iz]>=z0 and rows[iy]!=lastPos[1]+dy or rows[ix]!=lastPos[0] ):
if lastPos not in cdata:
cdata = cdata + [lastPos]
if [rows[ix], rows[iy]] not in cdata:
cdata = cdata + [[rows[ix], rows[iy]]]
#
#
# now we have a contour set. we need to connect these to make a polygon.
# the way we've done this, lines can connect to nn or nnn lattice sites.
# start with a random point in cdata (maybe the first point?).
# it does not matter which direction we go; we just can't backtrack.
# --> this basic method, but instead employing an index (ie, the xy index)
# would probably be faster. the yx scan should probably calculate and use
# the xy index as well...
#
#just in case (this might take a long time, so should maybe be skipped)
#print "starting set"
#cdata = set(cdata)
#print "finishing set"
#
return cdata
#
# oops... this method will not always outline a polygon...
'''
polyPairs = []
currentPoly = [] # current polygon. eventually, we'll reconnect to the first polygon, then we'll delete these records from cdata.
rows = cdata[0]
checkPoint = []
fromPoint = []
for rowsis in cdata:
# look for nn or nnn point:
foundPoint = 0
#
#print rows[0]
#print rows[0]+dx
checkPoint = [rows[0]findHeadTailInTuples(thisSeg, rightSegs)[1]>=0+dx, rows[1]]
if checkPoint in cdata and foundPoint==0 and checkPoint!=fromPoint:
foundPoint=1
nextPoint = checkPoint
#
checkPoint = [rows[0]+dx, rows[1]+dy]
if checkPoint in cdata and foundPoint==0 and checkPoint!=fromPoint:
foundPoint=1
nextPoint = checkPoint
#
checkPoint = [rows[0], rows[1]+dy]
if checkPoint in cdata and foundPoint==0 and checkPoint!=fromPoint:
foundPoint=1
nextPoint = checkPoint
#
checkPoint = [rows[0]-dx, rows[1]+dy]
if checkPoint in cdata and foundPoint==0 and checkPoint!=fromPoint:
foundPoint=1
nextPoint = checkPoint
#
checkPoint = [rows[0]-dx, rows[1]]
if checkPoint in cdata and foundPoint==0 and checkPoint!=fromPoint:
foundPoint=1
nextPoint = checkPoint
#
checkPoint = [rows[0]-dx, rows[1]-dy]
if checkPoint in cdata and foundPoint==0 and checkPoint!=fromPoint:
foundPoint=1
nextPoint = checkPoint
#
checkPoint = [rows[0], rows[1]-dy]
if checkPoint in cdata and foundPoint==0 and checkPoint!=fromPoint:
foundPoint=1
nextPoint = checkPoint
#
checkPoint = [rows[0]+dx, rows[1]-dy]
if checkPoint in cdata and foundPoint==0 and checkPoint!=fromPoint:
foundPoint=1
nextPoint = checkPoint
#
polyPairs = polyPairs + [[rows[0], rows[1], nextPoint[0], nextPoint[1]]]
rows = [nextPoint[0], nextPoint[1]]
fromPoint = [rows[0], rows[1]]
#
return polyPairs
'''
#