1
2
3
4
5
6
7
8
9 from NetworkEditor.items import NetworkNode
10 import Numeric
11
12
14
16 kw['name'] = name
17 apply( NetworkNode.__init__, (self,), kw)
18
19 code = """def doit(self, in1):
20 import Numeric
21 l = len(in1)
22 dm = Numeric.zeros( (l,l), 'd')
23 in1 = Numeric.array(in1).astype('d')
24 for i in range(l):
25 dist = in1[i] - in1
26 dist = dist*dist
27 dm[i] = Numeric.sqrt(Numeric.sum(dist, 1))
28 self.outputData(out1=dm)\n"""
29
30 if code: self.setFunction(code)
31
32 self.inputPortsDescr.append({'name': 'in1', 'datatype': 'None'})
33 self.outputPortsDescr.append({'name': 'out1', 'datatype': 'None'})
34
35
36 -class DDM(NetworkNode):
37
39 kw['name'] = name
40 apply( NetworkNode.__init__, (self,), kw)
41
42 code = """def doit(self, in1, in2):
43 import Numeric
44 result = in1-in2
45 self.outputData(out1=result)\n"""
46
47 if code: self.setFunction(code)
48
49 self.inputPortsDescr.append({'name': 'in1', 'datatype': 'None'})
50 self.inputPortsDescr.append({'name':'in2', 'datatype': 'None'})
51 self.outputPortsDescr.append({'name':'out1', 'datatype': 'None'})
52
53
54
56
57 - def __init__(self, name='cluster', **kw):
58 kw['name'] = name
59 apply( NetworkNode.__init__, (self,), kw)
60
61 code = """def doit(self, in1, cut_off):
62 import math
63 mat = in1
64 clusters = [[0],] # 1 cluster with first point
65 l = mat.shape[0]
66 for i1 in range(1, l):
67 for c in clusters: # loop over excisting clusters
68 inclus = 1
69 for p in c: # check distance to all points in cluster
70 if math.fabs(mat[i1,p]) > cut_off:
71 inclus=0
72 break
73 if inclus: # all dist. below cut_off --> add to cluster
74 c.append(i1)
75 inclus = 1
76 break
77 if not inclus: # after trying all clusters we failed -> new cluster
78 clusters.append([i1])
79 # make it 1 based so indices match PMV residue indices
80 #clusters1 = []
81 #for e in clusters:
82 # clusters1.append( list ( Numeric.array(e) + 1 ) )
83 self.outputData(out1=clusters)\n"""
84
85 if code: self.setFunction(code)
86
87 self.widgetDescr['cut_off'] = {
88 'class': 'NEDial', 'master': 'node', 'size': 50,
89 'oneTurn': 4.0, 'type': float, 'showLabel': 1, 'precision': 2,
90 'labelCfg':{'text':'cut_off'}, 'labelSide':'left'}
91
92 self.inputPortsDescr.append({'name':'in1', 'datatype':'None'})
93 self.inputPortsDescr.append({'datatype':'None', 'name':'cut_off'})
94 self.outputPortsDescr.append({'name':'out1', 'datatype': 'None'})
95
96
98
99 - def __init__(self, name='color cluster', **kw):
100 kw['name'] = name
101 apply( NetworkNode.__init__, (self,), kw)
102
103 code = """def doit(self, in1):
104 from DejaVu.colorTool import RGBRamp, Map
105 cols = Map(range(len(in1)), RGBRamp() )
106 l = len(reduce(lambda x,y: x+y, in1))
107 c = Numeric.zeros( (l,3), 'f' )
108 i=0
109 for e in in1:
110 col = cols[i]
111 for p in e:
112 c[p] = col
113 i = i + 1
114 self.outputData(out1=c)\n"""
115
116 if code: self.setFunction(code)
117
118 self.inputPortsDescr.append({'name':'in1', 'datatype': 'None'})
119 self.outputPortsDescr.append({'name':'out1', 'datatype': 'None'})
120
121
123
124 - def __init__(self, name='default indices', **kw):
125 apply( NetworkNode.__init__, (self,), kw)
126
127 code = """def doit(self, in1):
128 self.outputData(out1=[range(in1[0])])\n"""
129 if code: self.setFunction(code)
130
131 self.inputPortsDescr.append({'name':'length', 'datatype':'int'})
132 self.outputPortsDescr.append({'name':'out1', 'datatype':'None'})
133
134
135 from Vision.VPE import NodeLibrary
136
137 flexlib = NodeLibrary('Flex', '#AA66AA')
138 flexlib.addNode(DistanceMatrix, 'DM', 'Input')
139 flexlib.addNode(DDM, 'DDM', 'Input')
140 flexlib.addNode(Cluster, 'Cluster', 'Input')
141 flexlib.addNode(ColorCluster, 'Color Cluster', 'Input')
142 flexlib.addNode(DefaultIndices, 'indices', 'Input')
143