-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPWPsiLine.py
79 lines (59 loc) · 2.56 KB
/
PWPsiLine.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
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.lines
import numpy as np
from hyperbola import LineBase
class PWPsiLine(LineBase):
cols = ["black", "red"]
def __init__(self,F1,F2, data, config, **kwargs):
"""creates a pairwise psi line. the convention here is that the line is always left to right"""
LineBase.__init__(self, F1, F2, data, config,
**kwargs)
weight = self.c.psi_lwd
threshold = self.c.psi_threshold
psi = self.d.get_default_stat(F1.pop, F2.pop)
self.set_color(self.cols[psi>0])
self.set_lw(abs(psi * weight))
if abs(psi) * weight < threshold:
self.set_visible(False)
assert self.F1[0] < self.F2[0] or (self.F1[0] == self.F2[0] and self.F1[1] < self.F2[1])
def getCoords(self):
if self.F1[0] > self.F2[0] or \
(self.F1[0] == self.F2[0] and self.F1[1] > self.F2[1]):
print "%f>%f or %f>%f"%(self.F1[0], self.F2[0], self.F1[1], self.F2[1])
print "SWITCH"
self.F1, self.F2 = self.F2,self.F1
self.set_color( self.cols[ self.d.get_default_stat(self.F1.pop,self.F2.pop) >0])
coords = np.array([[self.F1[0],self.F1[1]],
[self.F2[0],self.F2[1]]])
assert self.F1[0] < self.F2[0] or \
(self.F1[0] == self.F2[0] and self.F1[1] < self.F2[1])
return coords
def update_(self,F1=None, F2=None):
"""
updates the plot and all lines. If F1, F2 are passed they are updated as well, otherwise the config element is used
"""
visible = self.get_visible( )
# first, update everything
if F1 is not None:
self.F1 = F1
if F2 is not None:
self.F2 = F2
if self.F1[0] > self.F2[0]:
self.F1, self.F2 = self.F2,self.F1
self.set_color( self.cols[ self.d.get_default_stat(self.F1.pop,self.F2.pop)>0] )
psi = self.d.get_default_stat(self.F1, self.F2)
self.set_linewidth(self.c.psi_lwd * psi)
if self.c.psi_lwd * abs(psi) > self.c.psi_threshold \
and self.F1.is_active() and self.F2.is_active():
visible = True
else:
visible = False
if self.F1.cluster != self.F2.cluster:
visible = False
self.set_visible ( visible )
#print "LINEREDRAW: psi: %s, weight: %s (%s) threshold %s"%(visible, self.weight, 0, self.threshold)
#then, update
v = self.getCoords()
self.set_xdata(v[:,0])
self.set_ydata(v[:,1])