visbrain.objects.CrossSecObj

class visbrain.objects.CrossSecObj(name, vol=None, hdr=None, coords=None, contrast=0.0, interpolation='nearest', text_size=13.0, text_color='white', text_bold=True, transform=None, parent=None, verbose=None, preload=True, **kw)[source][source]

Create a Cross-sections object.

Parameters
namestring

Name of the ROI object. If name is ‘brodmann’, ‘aal’ or ‘talairach’ a predefined ROI object is used and vol, index and label are ignored.

volarray_like | None

The volume to use for the cross-section. Sould be an array with three dimensions.

coordstuple | None

The MNI coordinates of the point where the cut is performed. Must be a tuple of three floats for (x, y, z).

contrastfloat | 0.

The contrast of the background image 0. <= contrast <= 1.

interpolationstring | ‘nearest’

Interpolation method for the image. See vispy.scene.visuals.Image for availables interpolation methods. Use ‘nearest’ for no interpolation.

text_sizefloat | 13.

Text size to use.

text_colorstring/tuple | ‘white’

Text color.

text_boldbool | True

Use bold text.

transformVisPy.visuals.transforms | None

VisPy transformation to set to the parent node.

parentVisPy.parent | None

ROI object parent.

verbosestring

Verbosity level.

Notes

List of supported shortcuts :

  • s : save the figure

  • +, - : Increase / decrease contrast.

  • x, X : Move along the x-axis.

  • y, Y : Move along the y-axis

  • z, Z : Move along the z-axis

  • c : Display / hide the cross.

Examples

>>> import numpy as np
>>> from visbrain.objects import CrossSecObj
>>> r = CrossSecObj('brodmann', coords=(10., -10., 20.))
>>> r.preview(axis=True)

Methods

__init__(name[, vol, hdr, coords, contrast, …])

Init.

animate([step, interval, iterations])

Animate the object.

copy()

Get a copy of the object.

cut_coords([coords])

Cut at a specific MNI coordinate.

describe_tree()

Tree description.

highlight_sources(xyz[, radius, color])

Highlight a number of sources.

list([file])

Get the list of installed volumes.

localize_source(coords)

Cut at a specific MNI coordinate and display the cross.

pos_to_slice(pos[, axis, hdr])

Return the slice from position.

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.

remove()

Remove the volume template.

render()

Render the canvas.

save([tmpfile])

Save the volume template.

screenshot(saveas[, print_size, dpi, unit, …])

Take a screeshot of the scene.

set_activation(data[, xyz, translucent, …])

Set any type of additional data (activation, stat…).

set_shortcuts_to_canvas(canvas)

Set shortcuts to a VisbrainCanvas.

slice_to_pos(sl[, axis, hdr])

Return the position from slice in the volume space.

to_dict()

Return a dictionary of all colorbar args.

to_kwargs([addisminmax])

Return a dictionary for input arguments.

update()

Fonction to run when an update is needed.

update_from_dict(kwargs)

Update attributes from a dictionary.

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

Animate the object.

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

Parameters
stepfloat | 1.

Rotation step.

intervalfloat | ‘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.

iterationsint | -1

Number of iterations. Can be -1 for infinite.

axial

Get the axial value.

cmap

Get the cmap value.

contrast

Get the contrast value.

copy()[source]

Get a copy of the object.

coronal

Get the coronal value.

cut_coords(coords=None)[source][source]

Cut at a specific MNI coordinate.

Parameters
coordstuple | None

The MNI coordinates of the point where the cut is performed. Must be a tuple of three floats for (x, y, z).

data_folder

Get the data_folder value.

highlight_sources(xyz, radius=1, color='green')[source][source]

Highlight a number of sources.

Parameters
xyzarray_like | None

Array of sources coordinates. This array must have a shape of (n_sources, 3).

radiusint | 1

Default radius size to display in the IRM.

colorstring | ‘green’

Sources color.

interpolation

Get the interpolation value.

list(file=None)[source]

Get the list of installed volumes.

localize_source(coords)[source][source]

Cut at a specific MNI coordinate and display the cross.

Parameters
coordstuple | None

The MNI coordinates of the point where the cut is performed. Must be a tuple of three floats for (x, y, z).

name

Get the name value.

parent

Get the parent value.

pos_to_slice(pos, axis=None, hdr=None)[source]

Return the slice from position.

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

Previsualize the result.

Parameters
bgcolorarray_like/string/tuple | ‘black’

Background color for the preview.

axisbool | False

Add x and y axis with ticks.

xyzbool | False

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

objVisbrainObj | None

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

sizetuple | (1200, 800)

Default size of the window.

mplbool | False

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

kwargsdict | {}

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
namestring

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

n_picint | 10

Number of pictures to use to render the gif.

bgcolorstring, tuple, list | None

Background color.

remove()[source]

Remove the volume template.

render()[source]

Render the canvas.

Returns
imgarray_like

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

sagittal

Get the sagittal value.

save(tmpfile=False)[source]

Save the volume template.

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
saveasstr

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

print_sizetuple | 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.

dpifloat | 300.

Dots per inch for printing the image.

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

Unit of the printed size.

factorfloat | None

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

regiontuple | None

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

autocropbool | False

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

bgcolorarray_like/string | None

The background color of the image.

transparentbool | False

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

objVisbrainObj | None

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

kwargsdict | {}

Optional arguments are passed to the VisbrainCanvas class.

set_activation(data, xyz=None, translucent=(None, 0.5), cmap='Spectral_r', clim=None, vmin=None, vmax=None, under='red', over='green')[source][source]

Set any type of additional data (activation, stat…).

Parameters
datastring

Full path to the nifti file.

xyzarray_like | None

Coordinate of a point to center the cross-sections.

translucenttuple | None

Set a specific range translucent. With f_1 and f_2 two floats, if translucent is :

  • (f_1, f_2) : values between f_1 and f_2 are set to translucent

  • (None, f_2) x <= f_2 are set to translucent

  • (f_1, None) f_1 <= x are set to translucent

cmapstring | ‘Spectral_r’

Colormap to use.

climtuple | None

Colorbar limits.

vminfloat | None

Lower threshold.

understring | ‘red’

Color to use for every values under vmin.

vmaxfloat | None

Over threshold.

overstring | ‘green’

Color to use for every values over vmax.

slice_to_pos(sl, axis=None, hdr=None)[source]

Return the position from slice in the volume space.

text_size

Get the text_size value.

transform

Get the transform value.

visible_obj

Get the visible_obj value.