visbrain.objects.ConnectObj

class visbrain.objects.ConnectObj(name, nodes, edges, select=None, line_width=3.0, color_by='strength', custom_colors=None, alpha=1.0, antialias=False, dynamic=None, dynamic_order=1, dynamic_orientation='ascending', cmap='viridis', clim=None, vmin=None, vmax=None, under='gray', over='red', transform=None, parent=None, verbose=None, _z=-10.0, **kw)[source][source]

Create a connectivity object.

Parameters:
name : string

The name of the connectivity object.

nodes : array_like

Array of nodes coordinates of shape (n_nodes, 3).

edges : array_like | None

Array of ponderations for edges of shape (n_nodes, n_nodes).

select : array_like | None

Array to select edges to display. This should be an array of boolean values of shape (n_nodes, n_nodes).

line_width : float | 3.

Connectivity line width.

color_by : {‘strength’, ‘count’, ‘causal’}

Coloring method:

  • ‘strength’ : color edges according to their connection strength define by the edges input. Only the upper triangle of the connectivity array is considered.
  • ‘count’ : color edges according to the number of connections per node. Only the upper triangle of the connectivity array is considered.
  • ‘causal’ : color edges according to the connectivity strength but this time, the upper and lower triangles of the connectivity array in edges are considered.
custom_colors : dict | None

Use a dictionary to colorize edges. For example, {1.2: ‘red’, 2.8: ‘green’, None: ‘black’} turn connections that have a 1.2 and 2.8 strength into red and green. All others connections are set to black.

alpha : float | 1.

Transparency level (if dynamic is None).

antialias : bool | False

Use smoothed lines.

dynamic : tuple | None

Control the dynamic opacity. For example, if dynamic=(0, 1), strong connections will be more opaque than weaker connections.

dynamic_order : int | 1

If 1, the dynamic transparency is linearly modulated by the connectivity. If 2, the transparency follow a x**2 curve etc.

dynamic_orientation : str | ‘ascending’

Define the transparency behavior :

  • ‘ascending’ : from translucent to opaque
  • ‘center’ : from opaque to translucent and finish by opaque
  • ‘descending’ ; from opaque to translucent
cmap : string | ‘viridis’

Colormap to use if custom_colors is None.

vmin : float | None

Lower threshold of the colormap if custom_colors is None.

under : string | None

Color to use for values under vmin if custom_colors is None.

vmin : float | None

Higher threshold of the colormap if custom_colors is None.

over : string | None

Color to use for values over vmax if custom_colors is None.

transform : VisPy.visuals.transforms | None

VisPy transformation to set to the parent node.

parent : VisPy.parent | None

Line object parent.

verbose : string

Verbosity level.

_z : float | 10.

In case of (n_sources, 2) use _z to specify the elevation.

kw : dict | {}

Optional arguments are used to control the colorbar (See ColorbarObj).

Notes

List of supported shortcuts :

  • s : save the figure
  • <delete> : reset camera

Examples

>>> import numpy as np
>>> from visbrain.objects import ConnectObj
>>> n_nodes = 100
>>> nodes = np.random.rand(n_nodes, 3)
>>> edges = np.random.uniform(low=-10., high=10., size=(n_nodes, n_nodes))
>>> select = np.logical_and(edges >= 0, edges <= 1.)
>>> c = ConnectObj('Connect', nodes, edges, select=select, cmap='inferno',
>>>                antialias=True)
>>> c.preview(axis=True)

Methods

__init__(name, nodes, edges[, select, …]) Init.
analyse_connections([roi_obj, group_by, …]) Analyse connections.
animate([step, interval, iterations]) Animate the object.
copy() Get a copy of the object.
describe_tree() Tree description.
get_nb_connections_per_node([sort, order]) Get the number of connections per node.
preview([bgcolor, axis, xyz, show, obj, …]) Previsualize the result.
record_animation(name[, n_pic, bgcolor]) Record an animated object and save as a *.gif file.
render() Render the canvas.
screenshot(saveas[, print_size, dpi, unit, …]) Take a screeshot of the scene.
set_shortcuts_to_canvas(canvas) Set shortcuts to a VisbrainCanvas.
to_dict() Return a dictionary of all colorbar args.
to_kwargs([addisminmax]) Return a dictionary for input arguments.
update() Update the line.
update_from_dict(kwargs) Update attributes from a dictionary.
alpha

Get the alpha value.

analyse_connections(roi_obj='talairach', group_by=None, get_centroids=False, replace_bad=True, bad_patterns=[-1, 'undefined', 'None'], distance=None, replace_with='Not found', keep_only=None)[source][source]

Analyse connections.

Parameters:
roi_obj : string/list | ‘talairach’

The ROI object to use. Use either ‘talairach’, ‘brodmann’ or ‘aal’ to use a predefined ROI template. Otherwise, use a RoiObj object or a list of RoiObj.

group_by : str | None

Name of the column inside the dataframe for gouping connectivity results.

replace_bad : bool | True

Replace bad values (True) or not (False).

bad_patterns : list | [-1, ‘undefined’, ‘None’]

Bad patterns to replace if replace_bad is True.

replace_with : string | ‘Not found’

Replace bad patterns with this string.

keep_only : list | None

List of string patterns to keep only sources that match.

Returns:
df : pandas.DataFrames

A Pandas DataFrame or a list of DataFrames if roi_obj is a list.

animate(step=1.0, interval='auto', iterations=-1)[source]

Animate the object.

Note that this method can only be used with 3D objects.

Parameters:
step : float | 1.

Rotation step.

interval : float | ‘auto’

Time between events in seconds. The default is ‘auto’, which attempts to find the interval that matches the refresh rate of the current monitor. Currently this is simply 1/60.

iterations : int | -1

Number of iterations. Can be -1 for infinite.

cmap

Get the cmap value.

color_by

Get the color_by value.

copy()[source]

Get a copy of the object.

data_folder

Get the data_folder value.

dynamic

Get the dynamic value.

get_nb_connections_per_node(sort='index', order='ascending')[source][source]

Get the number of connections per node.

Parameters:
sort : {‘index’, ‘count’}

Sort either by node index (‘index’) or according to the number of connections per node (‘count’).

order : {‘ascending’, ‘descending’}

Get the number of connections per node

line_width

Get the line_width value.

name

Get the name value.

parent

Get the parent value.

preview(bgcolor='black', axis=False, xyz=False, show=True, obj=None, size=(1200, 800), mpl=False, **kwargs)[source]

Previsualize the result.

Parameters:
bgcolor : array_like/string/tuple | ‘black’

Background color for the preview.

axis : bool | False

Add x and y axis with ticks.

xyz : bool | False

Add an (x, y, z) axis to the scene.

obj : VisbrainObj | None

Pass a Visbrain object if you want to use the camera of an other object.

size : tuple | (1200, 800)

Default size of the window.

mpl : bool | False

Use Matplotlib to display the object. This result in a non interactive figure.

kwargs : dict | {}

Optional arguments are passed to the VisbrainCanvas class.

record_animation(name, n_pic=10, bgcolor=None)[source]

Record an animated object and save as a *.gif file.

Note that this method :

  • Can only be used with 3D objects.
  • Requires the python package imageio
Parameters:
name : string

Name of the gif file (e.g ‘myfile.gif’)

n_pic : int | 10

Number of pictures to use to render the gif.

bgcolor : string, tuple, list | None

Background color.

render()[source]

Render the canvas.

Returns:
img : array_like

Array of shape (n_rows, n_columns, 4) where 4 describes the RGBA components.

screenshot(saveas, print_size=None, dpi=300.0, unit='centimeter', factor=None, region=None, autocrop=False, bgcolor=None, transparent=False, obj=None, line_width=1.0, **kwargs)[source]

Take a screeshot of the scene.

By default, the rendered canvas will have the size of your screen. The screenshot() method provides two ways to increase to exported image resolution :

  • Using print_size, unit and dpi inputs : specify the size of the image at a specific dpi level. For example, you might want to have an (10cm, 15cm) image at 300 dpi.
  • Using the factor input : multiply the default image size by this factor. For example, if you have a (1920, 1080) monitor and if factor is 2, the exported image should have a shape of (3840, 2160) pixels.
Parameters:
saveas : str

The name of the file to be saved. This file must contains a extension like .png, .tiff, .jpg…

print_size : tuple | None

The desired print size. This argument should be used in association with the dpi and unit inputs. print_size describe should be a tuple of two floats describing (width, height) of the exported image for a specific dpi level. The final image might not have the exact desired size but will try instead to find a compromize regarding to the proportion of width/height of the original image.

dpi : float | 300.

Dots per inch for printing the image.

unit : {‘centimeter’, ‘millimeter’, ‘pixel’, ‘inch’}

Unit of the printed size.

factor : float | None

If you don’t want to use the print_size input, factor simply multiply the resolution of your screen.

region : tuple | None

Select a specific region. Must be a tuple of four integers each one describing (x_start, y_start, width, height).

autocrop : bool | False

Automaticaly crop the figure in order to have the smallest space between the brain and the border of the picture.

bgcolor : array_like/string | None

The background color of the image.

transparent : bool | False

Specify if the exported figure have to contains a transparent background.

obj : VisbrainObj | None

Pass a Visbrain object if you want to use the camera of an other object for the sceen rendering.

kwargs : dict | {}

Optional arguments are passed to the VisbrainCanvas class.

transform

Get the transform value.

visible_obj

Get the visible_obj value.