:py:mod:`AFQ.viz.plotly_backend` ================================ .. py:module:: AFQ.viz.plotly_backend Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: AFQ.viz.plotly_backend.Axes Functions ~~~~~~~~~ .. autoapisummary:: AFQ.viz.plotly_backend._inline_interact AFQ.viz.plotly_backend._to_color_range AFQ.viz.plotly_backend._color_arr2str AFQ.viz.plotly_backend.set_layout AFQ.viz.plotly_backend._draw_streamlines AFQ.viz.plotly_backend._plot_profiles AFQ.viz.plotly_backend.visualize_bundles AFQ.viz.plotly_backend.create_gif AFQ.viz.plotly_backend._draw_roi AFQ.viz.plotly_backend.visualize_roi AFQ.viz.plotly_backend._draw_slice AFQ.viz.plotly_backend._name_from_enum AFQ.viz.plotly_backend.visualize_volume AFQ.viz.plotly_backend._draw_core AFQ.viz.plotly_backend.single_bundle_viz Attributes ~~~~~~~~~~ .. autoapisummary:: AFQ.viz.plotly_backend.scope AFQ.viz.plotly_backend.viz_logger .. py:data:: scope .. py:data:: viz_logger .. py:function:: _inline_interact(figure, show, show_inline) Helper function to reuse across viz functions .. !! processed by numpydoc !! .. py:function:: _to_color_range(num) .. py:function:: _color_arr2str(color_arr, opacity=1.0) .. py:function:: set_layout(figure, color=None) .. py:function:: _draw_streamlines(figure, sls, dimensions, color, name, cbv=None, cbs=None, sbv_lims=[None, None], flip_axes=[False, False, False], opacity=1.0) .. py:function:: _plot_profiles(profiles, bundle_name, color, fig, scalar) .. py:function:: 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) Visualize bundles in 3D :Parameters: **sft** : Stateful 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_points** : int or None n_points to resample streamlines to before plotting. If None, no resampling is done. **bundle** : str, optional The name of a bundle to select or an integer for selection from the sft metadata. **colors** : dict 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_volume** : ndarray 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_streamline** : ndarray 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_viz** : int 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_lims** : ndarray 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_profiles** : Tuple 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_axes** : ndarray 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] **opacity** : float Float between 0 and 1 defining the opacity of the bundle. Default: 1.0 **background** : tuple, optional RGB values for the background. Default: (1, 1, 1), which is white background. **figure** : Plotly Figure object, optional If provided, the visualization will be added to this Figure. Default: Initialize a new Figure. **interact** : bool Whether to open the visualization in an interactive window. Default: False **inline** : bool Whether to embed the interactivevisualization inline in a notebook. Only works in the notebook context. Default: False. :Returns: Plotly Figure object .. .. !! processed by numpydoc !! .. py:function:: create_gif(figure, file_name, n_frames=30, zoom=2.5, z_offset=0.5, size=(600, 600)) 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) .. !! processed by numpydoc !! .. py:function:: _draw_roi(figure, roi, name, color, opacity, dimensions, flip_axes) .. py:function:: 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) Render a region of interest into a volume :Parameters: **roi** : str or Nifti1Image The ROI information **affine_or_mapping** : ndarray, 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' **color** : ndarray, optional RGB color for ROI. Default: np.array([0.9999, 0, 0]) **opacity** : float, optional Opacity of ROI. Default: 1.0 **flip_axes** : ndarray 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] **figure** : Plotly Figure object, optional If provided, the visualization will be added to this Figure. Default: Initialize a new Figure. **interact** : bool Whether to open the visualization in an interactive window. Default: False **inline** : bool Whether to embed the interactive visualization inline in a notebook. Only works in the notebook context. Default: False. :Returns: Plotly Figure object .. .. !! processed by numpydoc !! .. py:class:: Axes Bases: :py:obj:`enum.IntEnum` Enum where members are also (and must be) ints .. !! processed by numpydoc !! .. py:attribute:: X :value: 0 .. py:attribute:: Y :value: 1 .. py:attribute:: Z :value: 2 .. py:function:: _draw_slice(figure, axis, volume, opacity=0.3, pos=0.5, colorscale='greys', invert_colorscale=False) .. py:function:: _name_from_enum(axis) .. py:function:: 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]) Visualize a volume :Parameters: **volume** : ndarray or str 3d volume to visualize. **figure** : Plotly Figure object, optional If provided, the visualization will be added to this Figure. Default: Initialize a new Figure. **x_pos** : float 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_pos** : float 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_pos** : float 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 **opacity** : float, optional Opacity of slices. Default: 1.0 **colorscale** : string, optional Plotly colorscale to use to color slices. Default: "greys" **invert_colorscale** : bool, optional Whether to invert colorscale. Default: False **flip_axes** : ndarray 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] **interact** : bool Whether to open the visualization in an interactive window. Default: False **inline** : bool Whether to embed the interactive visualization inline in a notebook. Only works in the notebook context. Default: False. :Returns: Plotly Figure object .. .. !! processed by numpydoc !! .. py:function:: _draw_core(sls, n_points, figure, bundle_name, indiv_profile, labelled_points, dimensions, flip_axes) .. py:function:: single_bundle_viz(indiv_profile, sft, bundle, scalar_name, flip_axes=[False, False, False], labelled_nodes=[0, -1], figure=None, include_profile=False) Visualize a single bundle in 3D with core bundle and associated profile :Parameters: **indiv_profile** : ndarray A numpy array containing a tract profile for this bundle for a scalar. **sft** : Stateful 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. **bundle** : str or int The name of the bundle to be used as the label for the plot, and for selection from the sft metadata. **scalar_name** : str The name of the scalar being used. **flip_axes** : ndarray 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_nodes** : list or ndarray Which nodes to label. -1 indicates the last node. Default: [0, -1] **figure** : Plotly Figure object, optional If provided, the visualization will be added to this Figure. Default: Initialize a new Figure. **include_profile** : bool, optional If true, also plot the tract profile. Default: False :Returns: Plotly Figure object .. .. !! processed by numpydoc !!