Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 130 lines (101 sloc) 3.36 kB
32c651b @jackdawjackdaw updated wirefinder
authored
1 #!/usr/bin/python
2 ## ccs, cec24@phy.duke.edu
3 ## push cubes onto wires
4 import os
5 import sys
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
6 import math
32c651b @jackdawjackdaw updated wirefinder
authored
7 from collections import defaultdict
8
9 centFile = "centroids_fit.dat"
10
11 ## the min / max ranges for the centroid cloud
12 xminCloud = -3
13 xmaxCloud = 3
14 zminCloud = -3
15 zmaxCloud = 3
16 ## how many spatial bins? 32 say
17 nbinsX = 32
18 nbinsZ = 32
19 ## binsize
20 binSizeX = float(xmaxCloud - xminCloud) / nbinsX
21 binSizeZ = float(zmaxCloud - zminCloud) / nbinsZ
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
22 ## number of cm between wires...
23 ## set this at your own peril...
24 wireMinDist = 4E-2
32c651b @jackdawjackdaw updated wirefinder
authored
25
26
27
28 if( len(sys.argv) < 2):
29 print "# threads centroids onto wires"
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
30 print "# run with: <path_to_centroids_fit.dat> "
32c651b @jackdawjackdaw updated wirefinder
authored
31 sys.exit(-1)
32
33 inpath = sys.argv[1]
34 infile = os.path.join(inpath, centFile)
35
36 print "# binsizeX: " + str(binSizeX) + " binsizeZ: " + str(binSizeZ)
37
38 class CubeOid:
39 """ a cuboid, has a centroid and an index """
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
40 def __init__(self, index, cx, cy, cz, th):
32c651b @jackdawjackdaw updated wirefinder
authored
41 self.index = index
42 self.cx = cx
43 self.cy = cy
44 self.cz = cz
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
45 self.th = th
46 def write(self):
47 retstring = str(self.index) + " " + str(self.cx) + " " + str(self.cy) + " " + str(self.cz) + " " + str(self.th)
48 return retstring
49
50
51 def dist(this, other):
52 dx = math.fabs(this.cx - other.cx)
53 dz = math.fabs(this.cz - other.cz)
54 return math.sqrt(dx*dx + dz*dz)
32c651b @jackdawjackdaw updated wirefinder
authored
55
56
57 centList = []
58
59 ## now we want to bin the centroids by x,z coordinate
60 xzBinDict = defaultdict(list)
61
62
63 #maxCount = 5
64 count = 0
65
66 centFile = open(infile, 'r')
67 for line in centFile:
68 temp = line.split(" ")
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
69 #print(temp)
70 tempCent = CubeOid(int(temp[0]), float(temp[2]), float(temp[3]), float(temp[4]), float(temp[5].rstrip('\n')))
32c651b @jackdawjackdaw updated wirefinder
authored
71 centList.append(tempCent)
72 count = count + 1
73 #if(count > maxCount):
74 # break
75
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
76 #print centList
32c651b @jackdawjackdaw updated wirefinder
authored
77
78 ## bin cubeoids spatially, could really do this while loading them...
79 for cent in centList:
80 binX = round(cent.cx / binSizeX)
81 binZ = round(cent.cz / binSizeZ)
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
82 # print "# xbin: " + str(binX) + " zbin: " + str(binZ)
32c651b @jackdawjackdaw updated wirefinder
authored
83 xzBinDict[(binX, binZ)].append(cent)
84
85 ## humm not sure this is worked quite right
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
86 wireCount = 0
87 bucketList = []
32c651b @jackdawjackdaw updated wirefinder
authored
88 for k,v in enumerate(xzBinDict):
89 print k, v, len(xzBinDict[v])
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
90 # grab the centroids from this bucket
91 tempList = xzBinDict[v]
92 for cent1 in tempList:
93 wireTemp = []
94 wireTemp.append(cent1)
95 tempList.remove(cent1)
96 for cent2 in tempList:
97 if(cent1 != cent2):
98 distance = dist(cent1, cent2)
99 if(distance < wireMinDist):
100 #print '\t', cent1.index, cent2.index, distance
101 wireTemp.append(cent2)
102 tempList.remove(cent2)
103
104 bucketList.append(wireTemp)
105 wireCount = wireCount + 1
106
107 ## this is pretty printing for user
108 wireCount = 0
109 for wire in bucketList:
110 print "wire: ", wireCount
111 for cent in wire:
112 print '\t', cent.index, cent.cx, cent.cy, cent.cz, cent.th
113 wireCount = wireCount + 1
114
115 ## lets output to file
116 outpath = os.path.join(inpath, "wires_list.dat")
117 outfile = open(outpath, 'w')
118
119 outfile.write("# wire_number, cluster_index, cx, cy, cz, theta\n")
120
121 wireCount = 0
122 for wire in bucketList:
123 for cent in wire:
124 outfile.write(str(wireCount)+ " " + cent.write() + "\n")
125 wireCount = wireCount + 1
32c651b @jackdawjackdaw updated wirefinder
authored
126
127
0f040ed @jackdawjackdaw wireFinder seems to work ok, clusters in xz plane
authored
128
129
Something went wrong with that request. Please try again.