-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbct_helper_widgets.py
More file actions
75 lines (60 loc) · 2.42 KB
/
Copy pathbct_helper_widgets.py
File metadata and controls
75 lines (60 loc) · 2.42 KB
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
import numpy as np
import ipywidgets as widgets
import k3d
from tvbwidgets.ui.head_widget import HeadWidget
from tvbwidgets.ui.connectivity_matrix_editor_widget import ConnectivityMatrixEditor
class BCTConnectivityMatrixEditor(ConnectivityMatrixEditor):
"""ConnectivityMatrixEditor stripped to weights tab only."""
def __init__(self, connectivity, **kwargs):
super().__init__(connectivity, **kwargs)
self.tab.children = [self.tab.children[0]]
self.tab.set_title(0, "weights")
class BCTTractLengthsMatrixEditor(ConnectivityMatrixEditor):
"""ConnectivityMatrixEditor stripped to tract_lengths tab only.
"""
def __init__(self, connectivity, **kwargs):
super().__init__(connectivity, **kwargs)
self.tab.children = [self.tab.children[1]]
self.tab.set_title(0, "tract_lengths")
class ColoredConnectivityHeadWidget(HeadWidget):
"""HeadWidget with per-node coloring driven by BCT metric values."""
def __init__(self, datatypes, node_values=None, region_labels=None, **kwargs):
self.node_values = node_values
self.region_labels = region_labels
super().__init__(datatypes, **kwargs)
def _HeadWidget__draw_connectivity(self, connectivity):
self._centres = connectivity.centres
self._labels = (
self.region_labels if self.region_labels is not None
else connectivity.region_labels
)
values = self.node_values if self.node_values is not None else np.ones(len(connectivity.centres))
values = np.array(values, dtype=float)
values[np.isinf(values)] = 0
values[np.isnan(values)] = 0
self._values = values
vmin, vmax = float(values.min()), float(values.max())
if vmin == vmax:
vmin -= 0.5
vmax += 0.5
self._points_obj = k3d.points(
connectivity.centres,
point_size=8,
shader='dot',
attribute=values,
color_map=k3d.matplotlib_color_maps.viridis,
color_range=[vmin, vmax],
)
edge_indices = np.nonzero(connectivity.weights)
edges = list(zip(edge_indices[0], edge_indices[1]))
lines = k3d.lines(
connectivity.centres,
indices=edges,
shader='simple',
color=0xffffff,
width=2,
)
self.plot += self._points_obj
self.plot += lines
def display(self):
pass