AFQ.viz.plotly_backend#

Module Contents#

Classes#

Axes

Enum where members are also (and must be) ints

Functions#

_inline_interact(figure, show, show_inline)

Helper function to reuse across viz functions

_to_color_range(num)

_color_arr2str(color_arr[, opacity])

set_layout(figure[, color])

_draw_streamlines(figure, sls, dimensions, color, name)

_plot_profiles(profiles, bundle_name, color, fig, scalar)

visualize_bundles(sft[, n_points, bundle, colors, ...])

Visualize bundles in 3D

create_gif(figure, file_name[, n_frames, zoom, ...])

Convert a Plotly Figure object into a gif

_draw_roi(figure, roi, name, color, opacity, ...)

visualize_roi(roi[, affine_or_mapping, static_img, ...])

Render a region of interest into a volume

_draw_slice(figure, axis, volume[, opacity, pos, ...])

_name_from_enum(axis)

visualize_volume(volume[, figure, x_pos, y_pos, ...])

Visualize a volume

_draw_core(sls, n_points, figure, bundle_name, ...)

single_bundle_viz(indiv_profile, sft, bundle, scalar_name)

Visualize a single bundle in 3D with core bundle and associated profile

Attributes#

scope

viz_logger

AFQ.viz.plotly_backend.scope[source]#
AFQ.viz.plotly_backend.viz_logger[source]#
AFQ.viz.plotly_backend._inline_interact(figure, show, show_inline)[source]#

Helper function to reuse across viz functions

AFQ.viz.plotly_backend._to_color_range(num)[source]#
AFQ.viz.plotly_backend._color_arr2str(color_arr, opacity=1.0)[source]#
AFQ.viz.plotly_backend.set_layout(figure, color=None)[source]#
AFQ.viz.plotly_backend._draw_streamlines(figure, sls, dimensions, color, name, cbv=None, cbs=None, sbv_lims=[None, None], flip_axes=[False, False, False], opacity=1.0)[source]#
AFQ.viz.plotly_backend._plot_profiles(profiles, bundle_name, color, fig, scalar)[source]#
AFQ.viz.plotly_backend.visualize_bundles(sft, n_points=None, bundle=None, colors=None, shade_by_volume=None, color_by_streamline=None, n_sls_viz=3600, sbv_lims=[None, None], include_profiles=(None, None), flip_axes=[False, False, False], opacity=1.0, figure=None, background=(1, 1, 1), interact=False, inline=False, **kwargs)[source]#

Visualize bundles in 3D

Parameters
sftStateful Tractogram, str

A Stateful Tractogram containing streamline information or a path to a trk file. In order to visualize individual bundles, the Stateful Tractogram must contain a bundle key in it’s data_per_streamline which is a list of bundle ‘uid’.

n_pointsint or None

n_points to resample streamlines to before plotting. If None, no resampling is done.

bundlestr, optional

The name of a bundle to select or an integer for selection from the sft metadata.

colorsdict or list

If this is a dict, keys are bundle names and values are RGB tuples. If this is a list, each item is an RGB tuple. Defaults to a dict from bundles to Tableau 20 RGB values.

shade_by_volumendarray or str, optional

3d volume use to shade the bundles. If None, no shading is performed. Only works when using the plotly backend. Default: None

color_by_streamlinendarray or dict, optional

N by 3 array, where N is the number of streamlines in sft; for each streamline you specify 3 values between 0 and 1 for rgb. If sft has multiple bundles, then use a dict for color_by_streamline, where keys are bundle names and values are n by 3 arrays. Overrides colors for bundles in the keys of the dict if passing a dict, or for all streamlines if using ndarray. Default: None

n_sls_vizint

Number of streamlines to randomly select if plotting all bundles. Selections will be proportional to the original number of streamlines per bundle. Default: 3600

sbv_limsndarray

Of the form (lower bound, upper bound). Shading based on shade_by_volume will only differentiate values within these bounds. If lower bound is None, will default to 0. If upper bound is None, will default to the maximum value in shade_by_volume. Default: [None, None]

include_profilesTuple of Pandas Dataframe and string

The first element of the uple is a Pandas Dataframe containing profiles in the standard pyAFQ output format for the bundle(s) being displayed. It will be used to generate a graph of the tract profiles for each bundle, with colors corresponding to the colors on the bundles. The string is the scalar to use from the profile. If these are None, no tract profiles will be graphed. Defualt: (None, None)

flip_axesndarray

Which axes to flip, to orient the image as RAS, which is how we visualize. For example, if the input image is LAS, use [True, False, False]. Default: [False, False, False]

opacityfloat

Float between 0 and 1 defining the opacity of the bundle. Default: 1.0

backgroundtuple, optional

RGB values for the background. Default: (1, 1, 1), which is white background.

figurePlotly Figure object, optional

If provided, the visualization will be added to this Figure. Default: Initialize a new Figure.

interactbool

Whether to open the visualization in an interactive window. Default: False

inlinebool

Whether to embed the interactivevisualization inline in a notebook. Only works in the notebook context. Default: False.

Returns
Plotly Figure object
AFQ.viz.plotly_backend.create_gif(figure, file_name, n_frames=30, zoom=2.5, z_offset=0.5, size=(600, 600))[source]#

Convert a Plotly Figure object into a gif

Parameters
figure: Plotly Figure object

Figure to be converted to a gif

file_name: str

File to save gif to.

n_frames: int, optional

Number of frames in gif. Will be evenly distributed throughout the rotation. Default: 60

zoom: float, optional

How much to magnify the figure in the fig. Default: 2.5

size: tuple, optional

Size of the gif. Default: (600, 600)

AFQ.viz.plotly_backend._draw_roi(figure, roi, name, color, opacity, dimensions, flip_axes)[source]#
AFQ.viz.plotly_backend.visualize_roi(roi, affine_or_mapping=None, static_img=None, roi_affine=None, static_affine=None, reg_template=None, name='ROI', figure=None, flip_axes=[False, False, False], color=np.array([0.9999, 0, 0]), opacity=1.0, interact=False, inline=False)[source]#

Render a region of interest into a volume

Parameters
roistr or Nifti1Image

The ROI information

affine_or_mappingndarray, Nifti1Image, or str, optional

An affine transformation or mapping to apply to the ROIs before visualization. Default: no transform.

static_img: str or Nifti1Image, optional

Template to resample roi to. Default: None

roi_affine: ndarray, optional

Default: None

static_affine: ndarray, optional

Default: None

reg_template: str or Nifti1Image, optional

Template to use for registration. Default: None

name: str, optional

Name of ROI for the legend. Default: ‘ROI’

colorndarray, optional

RGB color for ROI. Default: np.array([0.9999, 0, 0])

opacityfloat, optional

Opacity of ROI. Default: 1.0

flip_axesndarray

Which axes to flip, to orient the image as RAS, which is how we visualize. For example, if the input image is LAS, use [True, False, False]. Default: [False, False, False]

figurePlotly Figure object, optional

If provided, the visualization will be added to this Figure. Default: Initialize a new Figure.

interactbool

Whether to open the visualization in an interactive window. Default: False

inlinebool

Whether to embed the interactive visualization inline in a notebook. Only works in the notebook context. Default: False.

Returns
Plotly Figure object
class AFQ.viz.plotly_backend.Axes[source]#

Bases: enum.IntEnum

Enum where members are also (and must be) ints

X = 0[source]#
Y = 1[source]#
Z = 2[source]#
AFQ.viz.plotly_backend._draw_slice(figure, axis, volume, opacity=0.3, pos=0.5, colorscale='greys', invert_colorscale=False)[source]#
AFQ.viz.plotly_backend._name_from_enum(axis)[source]#
AFQ.viz.plotly_backend.visualize_volume(volume, figure=None, x_pos=0.5, y_pos=0.5, z_pos=0.5, interact=False, inline=False, opacity=0.3, colorscale='gray', invert_colorscale=False, flip_axes=[False, False, False])[source]#

Visualize a volume

Parameters
volumendarray or str

3d volume to visualize.

figurePlotly Figure object, optional

If provided, the visualization will be added to this Figure. Default: Initialize a new Figure.

x_posfloat or None, optional

Where to show Coronal Slice. If None, slice is not shown. Should be a decimal between 0 and 1. Indicatesthe fractional position along the perpendicular axis to the slice. Default: 0.5

y_posfloat or None, optional

Where to show Sagittal Slice. If None, slice is not shown. Should be a decimal between 0 and 1. Indicatesthe fractional position along the perpendicular axis to the slice. Default: 0.5

z_posfloat or None, optional

Where to show Axial Slice. If None, slice is not shown. Should be a decimal between 0 and 1. Indicatesthe fractional position along the perpendicular axis to the slice. Default: 0.5

opacityfloat, optional

Opacity of slices. Default: 1.0

colorscalestring, optional

Plotly colorscale to use to color slices. Default: “greys”

invert_colorscalebool, optional

Whether to invert colorscale. Default: False

flip_axesndarray

Which axes to flip, to orient the image as RAS, which is how we visualize. For example, if the input image is LAS, use [True, False, False]. Default: [False, False, False]

interactbool

Whether to open the visualization in an interactive window. Default: False

inlinebool

Whether to embed the interactive visualization inline in a notebook. Only works in the notebook context. Default: False.

Returns
Plotly Figure object
AFQ.viz.plotly_backend._draw_core(sls, n_points, figure, bundle_name, indiv_profile, labelled_points, dimensions, flip_axes)[source]#
AFQ.viz.plotly_backend.single_bundle_viz(indiv_profile, sft, bundle, scalar_name, flip_axes=[False, False, False], labelled_nodes=[0, -1], figure=None, include_profile=False)[source]#

Visualize a single bundle in 3D with core bundle and associated profile

Parameters
indiv_profilendarray

A numpy array containing a tract profile for this bundle for a scalar.

sftStateful Tractogram, str

A Stateful Tractogram containing streamline information. If bundle is an int, the Stateful Tractogram must contain a bundle key in it’s data_per_streamline which is a list of bundle `’uid’. Otherwise, the entire Stateful Tractogram will be used as the bundle for the visualization.

bundlestr or int

The name of the bundle to be used as the label for the plot, and for selection from the sft metadata.

scalar_namestr

The name of the scalar being used.

flip_axesndarray

Which axes to flip, to orient the image as RAS, which is how we visualize. For example, if the input image is LAS, use [True, False, False]. Default: [False, False, False]

labelled_nodeslist or ndarray

Which nodes to label. -1 indicates the last node. Default: [0, -1]

figurePlotly Figure object, optional

If provided, the visualization will be added to this Figure. Default: Initialize a new Figure.

include_profilebool, optional

If true, also plot the tract profile. Default: False

Returns
Plotly Figure object