Connectomes¶
NiiVue considers connectomes as a special class of meshes. While most meshes have fixed vertex positions (e.g. a brain is considered to have a fixed size), the radius of connectome nodes and edges can be scaled dynamically. The notebook mirrors the JavaScript connectome web page.
TODO: full notebook requires future ipyniivue: legend_line_thickness, edge_min, edge_max
In [1]:
import ipywidgets as widgets
from IPython.display import display
from ipyniivue import NiiVue
nv = NiiVue()
nv.load_volumes([{"path": "../images/mni152.nii.gz"}])
nv.load_meshes([
{"path": "../images/connectome.jcon"}
])
nv.set_clip_plane(0.1, 0, 135)
nv.opts.mesh_xray = 0.1
# Create UI
edge_scale_slider = widgets.FloatSlider(
value=1,
min=0.5,
max=3,
step=0.1,
description="Edge",
readout=False
)
def on_edge_scale_change(change):
"""Set size of edges."""
nv.meshes[0].edge_scale = change["new"]
edge_scale_slider.observe(on_edge_scale_change, names="value")
node_scale_slider = widgets.FloatSlider(
value=3,
min=0.5,
max=6,
step=0.1,
description="Node",
readout=False
)
def on_node_scale_change(change):
"""Set size of nodes."""
nv.meshes[0].node_scale = change["new"]
node_scale_slider.observe(on_node_scale_change, names="value")
legend_slider = widgets.IntSlider(
value=3,
min=0,
max=12,
description="Legend lines",
readout=False,
disabled=True
)
def on_legend_change(change):
"""Set size of legend lines."""
nv.meshes[0].legend_line_thickness = change["new"]
legend_slider.observe(on_legend_change, names="value")
stat_range = widgets.FloatRangeSlider(
value=[40, 80],
min=0.1,
max=120.0,
step=0.1,
continuous_update=True,
description="Threshold:",
readout=False
)
def on_stat_change(change):
"""Set threshold for statistical overlay."""
low, high = change["new"] # extract the two values
nv.volumes[0].cal_min = low
nv.volumes[0].cal_max = high
stat_range.observe(on_stat_change, names="value")
# Display
controls = widgets.HBox([edge_scale_slider, node_scale_slider, legend_slider, stat_range])
display(widgets.VBox([controls, nv]))
In [ ]:
In [ ]: