Skip to content

Commit

Permalink
Merge pull request #74 from peeplika/WID247
Browse files Browse the repository at this point in the history
WID-247 - SpaceTimeVisualizer widget
  • Loading branch information
liadomide authored Jul 24, 2024
2 parents cf20137 + 5ab6778 commit 8d113be
Show file tree
Hide file tree
Showing 4 changed files with 493 additions and 0 deletions.
63 changes: 63 additions & 0 deletions notebooks/ConnectivitySpaceTimeWidget.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Connectivity SpaceTime Widget\n",
"Displays a large scale Connectivity split into time slices, based on the delays of passing the signals to adjacent regions.The first slice is the complete weights matrix.<br><br>\n",
"This work has been produced as part of GSOC 2024.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from tvb.datatypes.connectivity import Connectivity\n",
"from tvbwidgets.ui.spacetime_widget import SpaceTimeVisualizerWidget\n",
"conn = Connectivity.from_file() # defaults to connectivy_76.zip\n",
"conn.configure()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = SpaceTimeVisualizerWidget(conn)\n",
"x.display()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "tvb-wid",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1 change: 1 addition & 0 deletions tvbwidgets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .ui.connectivity_react.connectivity_widget import ConnectivityWidgetReact
from .ui.dicom_widget import DicomWidget
from .ui.phase_plane_widget import PhasePlaneWidget
from .ui.spacetime_widget import SpaceTimeVisualizerWidget
from .ui.storage_widget import StorageWidget
from .ui.head_widget import HeadBrowser, HeadWidget, HeadWidgetConfig
from .ui.ts.mne_ts_widget import TimeSeriesWidgetMNE
Expand Down
122 changes: 122 additions & 0 deletions tvbwidgets/tests/test_spacetime_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import pytest
import numpy as np
import pythreejs as p3
import matplotlib
from ipywidgets import Tab, Output, BoundedFloatText, Text, HBox, HTML
from tvbwidgets.ui.spacetime_widget import SpaceTimeVisualizerWidget
from tvb.datatypes.connectivity import Connectivity

matplotlib.use('Agg')

@pytest.fixture
def connectivity():
conn = Connectivity.from_file()
conn.configure()
return conn

@pytest.fixture
def wid(connectivity):
widget = SpaceTimeVisualizerWidget(connectivity)
return widget

def test_display(wid):
wid.display()
assert isinstance(wid, SpaceTimeVisualizerWidget)

def test_prepare_widget(wid):
assert isinstance(wid.hbox, HBox)
assert len(wid.hbox.children) == 2
assert isinstance(wid.hbox.children[0], Tab)
assert isinstance(wid.hbox.children[1], HTML)
assert isinstance(wid.tab, Tab)
assert len(wid.tab.children) == 2
assert isinstance(wid.tab.children[0], Output)
assert isinstance(wid.tab.children[1], Output)
assert isinstance(wid.renderer, p3.Renderer)
assert isinstance(wid.fig, matplotlib.figure.Figure)

def test_prepare_scene(wid):
assert isinstance(wid.scene, p3.Scene)
assert isinstance(wid.camera, p3.PerspectiveCamera)
assert isinstance(wid.light, p3.AmbientLight)
assert isinstance(wid.key_light, p3.DirectionalLight)
assert isinstance(wid.picker, p3.Picker)
assert isinstance(wid.renderer, p3.Renderer)

def test_prepare_slices(wid):
assert len(wid.graph_slices) == 7
assert wid.graph_slices[0].material.map is not None
for i in range(7):
assert wid.graph_slices[i] in wid.scene.children

def tests_create_graph_slice(wid):
assert wid.graph_slices[0].geometry.height == 7.0
assert wid.graph_slices[0].geometry.width == 7.0
assert wid.graph_slices[0].geometry.depth == 0.1
for i in range(len(wid.graph_slices)):
z = -i*3 + 14 if i is 0 else -i*2 + 11 - 0.1*i*i
assert wid.graph_slices[i].position == (16.0, 0.0, z)

def test_generate_texture(wid):
for i in range(7):
texture = wid._generate_texture(i)
assert texture.format == "RGBFormat"
assert texture.data.shape == (76, 76, 3)


def test_generate_colors(wid):
colors = wid._generate_colors(wid.connectivity.weights)
assert colors is not None
assert colors.shape == (76, 76, 3)

def test_prepare_grid(wid):
wid._prepare_grid()
assert isinstance(wid.grid, p3.Mesh)
assert wid.grid.material.map is not None
assert wid.grid.material.transparent == True
assert wid.grid.position == (0, 0, 0)
assert wid.grid.name == "grid"
assert wid.grid.scale == (4, 3, 1)

def test_generate_gridlines(wid):
grid = wid._generate_gridlines()
assert grid.format == "RGBAFormat"
assert grid.data.shape == (76*5, 76*5, 4)

def test_prepare_connectivity(wid):
i = 2
connectivity = wid._prepare_connectivity(2)
assert connectivity.shape == (76, 76)

def test_create_matplotlib_graphs(wid):
assert len(wid.ims) == 7
assert len(wid.fig.axes) == 7
assert wid.fig.get_figheight() == 10.0
assert wid.fig.get_figwidth() == 14.0

def test_add_options(wid):
assert len(wid.options.children) == 4
assert isinstance(wid.options.children[0], BoundedFloatText)
assert isinstance(wid.options.children[1], BoundedFloatText)
assert isinstance(wid.options.children[2], BoundedFloatText)
assert isinstance(wid.options.children[3], Text)

assert wid.options.children[1].description == "from[ms]:"
assert wid.options.children[2].description == "to[ms]:"
assert wid.options.children[3].description == "selection[ms]:"
assert wid.options.children[0].value == 1.0
assert wid.options.children[0].description == "Conduction Speed:"
assert wid.options.children[1].value == 0.0
assert wid.options.children[1].min == 0.0
assert wid.options.children[1].max == 153.48574
assert wid.options.children[2].value == 153.48574
assert wid.options.children[2].min == 0.0
assert wid.options.children[2].max == 153.48574
assert wid.options.children[3].value == "None"







Loading

0 comments on commit 8d113be

Please sign in to comment.