API Documentation

class ipyniivue.widget.NiiVue(**kwargs: Any)[source]

Bases: OptionsMixin, AnyWidget

Represents a NiiVue widget instance.

This class provides a Jupyter widget for visualizing neuroimaging data using NiiVue. It inherits from OptionsMixin for default options.

__init__(height: int = 300, **options)[source]

Initialize the NiiVue widget.

Note: See the NiiVue.close() method to close the NiiVue widget and free up resources.

Parameters

heightint, optional

The height of the widget in pixels (default: 300).

**optionsdict, optional

Additional keyword arguments to configure the NiiVue widget. See ipyniivue.options_mixin.OptionsMixin for all options.

add_colormap(name: str, color_map: dict)[source]

Add a colormap to the widget.

Parameters

namestr

The name of the colormap.

color_mapdict

The colormap data.

Raises

ValueError

If the colormap does not meet the required format.

TypeError

If the colormap values are not of the correct type.

Examples

nv.add_colormap("custom_color_map", {
    "R": [0, 255, 0],
    "G": [0, 0, 255],
    "B": [0, 0, 0],
    "A": [0, 64, 64],
    "I": [0, 85, 255]
})
nv.set_colormap(nv.volumes[0].id, "custom_color_map")
add_mesh(mesh: Mesh)[source]

Add a single mesh to the widget.

Parameters

meshdict

A dictionary containing the mesh information.

Returns

None

Examples

nv = NiiVue()
nv.add_mesh({"path": "BrainMesh_ICBM152.lh.mz3"})
add_volume(volume: dict)[source]

Add a new volume to the widget.

Parameters

volumedict

A dictionary containing the volume information.

Returns

None

Examples

nv = NiiVue()
nv.add_volume({"path": "mni152.nii.gz"})
background_masks_overlays

An int trait.

clip_plane_depth_azi_elev

An instance of a Python list.

close()[source]

Close the NiiVue widget and free up resources.

This method disposes of the widget on both the frontend and backend. After calling this method, the widget will no longer be usable.

Examples

nv = NiiVue()
# use nv ...
nv.close()
close_drawing()[source]

Close the current drawing.

Examples

nv.close_drawing()
colormap_from_key(colormap_name: str) ColorMap[source]

Retrieve a colormap by name (case-insensitive).

Parameters

colormap_namestr

The name of the colormap to retrieve.

Returns

ColorMap

An instance of ColorMap corresponding to the given colormap name.

Examples

::

cmap = nv.colormap_from_key(‘Hot’)

colormaps()[source]

Retrieve the list of available colormap names.

Returns

list of str

A list containing the names of all available colormaps

Examples

colormaps = nv.colormaps()
draw_fill_overwrites

A boolean (True, False) trait.

draw_grow_cut()[source]

Dilate drawing so all voxels are colored.

Examples

nv.draw_grow_cut()
draw_lut

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

draw_opacity

A float trait.

draw_otsu(levels: int)[source]

Segment brain into specified number of levels using Otsu’s method.

This method removes dark voxels by segmenting the image into the specified number of levels.

Parameters

levelsint

Number of levels to segment the brain into (2-4).

Examples

nv.draw_otsu(3)
draw_undo()[source]

Restore drawing to previous state.

Examples

nv.draw_undo()
get_mesh_index_by_id(mesh_id: str) int[source]

Return the index of the mesh with the given id.

Parameters

mesh_idstr

The id of the mesh.

get_volume_index_by_id(volume_id: str) int[source]

Return the index of the volume with the given id.

Parameters

volume_idstr

The id of the volume.

height

An int trait.

id

A trait for unicode strings.

load_mat_cap_texture(png_data: bytes)[source]

Load matcap for illumination model.

Parameters

png_databytes

Image data binary.

Examples

matcap_path = './matcaps/gold.jpg'
with open(matcap_path, 'rb') as f:
    matcap_data = f.read()
nv.load_mat_cap_texture(matcap_data)
load_meshes(meshes: list)[source]

Load a list of meshes objects.

Parameters

mesheslist

A list of dictionaries containing the mesh information.

Returns

None

Examples

nv = NiiVue()
nv.load_meshes([{"path": "BrainMesh_ICBM152.lh.mz3"}])
load_volumes(volumes: list)[source]

Load a list of volume objects.

Parameters

volumeslist

A list of dictionaries containing the volume information.

Returns

None

Examples

nv = NiiVue()
nv.load_volumes([{"path": "mni152.nii.gz"}])
mesh_shader_names()[source]

Retrieve the list of available mesh shader names.

Returns

list of str

A list containing the names of all available mesh shader names

Examples

shaders = nv.mesh_shader_names()
property meshes

Returns the list of meshes.

Returns

list

A list of dictionairies containing the mesh information.

Examples

print(nv.meshes)
move_crosshair_in_vox(x: float, y: float, z: float)[source]

Move crosshair by a fixed number of voxels.

Parameters

xfloat

Translate left (-) or right (+)

yfloat

Translate posterior (-) or anterior (+)

zfloat

Translate inferior (-) or superior (+)

Examples

nv.move_crosshair_in_vox(1, 0, 0)
on_azimuth_elevation_change(callback, remove=False)[source]

Register a callback for the ‘azimuth_elevation_change’ event.

Set a callback function to run when the user changes the rotation of the 3D rendering.

Parameters

callbackcallable

A function that takes two arguments:

  • azimuth (float): The azimuth angle in degrees.

  • elevation (float): The elevation angle in degrees.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

def my_callback(azimuth, elevation):
    with out:
        print('Azimuth:', azimuth)
        print('Elevation:', elevation)

nv.on_azimuth_elevation_change(my_callback)
on_click_to_segment(callback, remove=False)[source]

Register a callback for the ‘click_to_segment’ event.

Set a callback function when clickToSegment is enabled and the user clicks on the image.

Parameters

callbackcallable

A function that takes one argument - a dict with the following keys:

  • mm3 (float): The segmented volume in cubic millimeters.

  • mL (float): The segmented volume in milliliters.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

def my_callback(data):
    with out:
        print('Clicked to segment')
        print('Volume mm3:', data['mm3'])
        print('Volume mL:', data['mL'])

nv.on_click_to_segment(my_callback)
on_clip_plane_change(callback, remove=False)[source]

Register a callback for the ‘clip_plane_change’ event.

Set a callback function to run when the user changes the clip plane.

Parameters

callbackcallable

A function that takes one argument - a list of numbers representing the clip plane.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_clip_plane_change
def my_callback(clip_plane):
    with out:
        print('Clip plane changed:', clip_plane)
on_document_loaded(callback, remove=False)[source]

Register a callback for the ‘document_loaded’ event.

Set a callback function to run when the user loads a new NiiVue document.

Parameters

callbackcallable

A function that takes one argument - a dict representing the loaded document with the following keys:

  • title (str): The title of the loaded document.

  • opts (dict): Options associated with the document.

  • volumes (list of str): A list of volume IDs loaded in the document.

  • meshes (list of str): A list of mesh IDs loaded in the document.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_document_loaded
def my_callback(document):
    with out:
        print('Document loaded:')
        print('Title:', document['title'])
        print('Options:', document['opts'])
        print('Volumes:', document['volumes'])
        print('Meshes:', document['meshes'])
on_drag_release(callback, remove=False)[source]

Register a callback for the ‘drag_release’ event.

Set a callback function to run when the right mouse button is released after dragging.

Parameters

callbackcallable

A function that takes one argument - a dict containing drag release parameters with the following keys:

  • frac_start (list of float): Starting fractional coordinates

    [X, Y, Z] before the drag.

  • frac_end (list of float): Ending fractional coordinates

    [X, Y, Z] after the drag.

  • vox_start (list of float): Starting voxel coordinates [X, Y, Z]

    before the drag.

  • vox_end (list of float): Ending voxel coordinates [X, Y, Z]

    after the drag.

  • mm_start (list of float): Starting coordinates in millimeters

    [X, Y, Z] before the drag.

  • mm_end (list of float): Ending coordinates in millimeters

    [X, Y, Z] after the drag.

  • mm_length (float): Length of the drag in millimeters.

  • tile_idx (int): Index of the image tile where the drag occurred.

  • ax_cor_sag (int): View index (axial=0, coronal=1, sagittal=2) where

    the drag occurred.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_drag_release
def my_callback(params):
    with out:
        print('Drag release event:', params)
on_frame_change(callback, remove=False)[source]

Register a callback for the ‘frame_change’ event.

Set a callback function to run whenever the current frame (timepoint) of a 4D image volume changes.

Parameters

callbackcallable

A function that takes two arguments:

  • volume (Volume): The image volume object that has changed frame.

  • frame_index (int): The index of the new frame.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_frame_change
def my_callback(volume, frame_index):
    with out:
        print('Frame changed')
        print('Volume:', volume)
        print('Frame index:', frame_index)
on_hover_idx_change(callback, remove=False)[source]

Register a callback for the ‘hover_idx_change’ event.

Set a callback function to run whenever the mouse moves over the canvas and the index (idx) values under the cursor position change.

This event provides the index (idx) values of the data under the cursor for all volumes. The callback function receives a dictionary containing the index values for each volume.

Parameters

callbackcallable

The function to call when the event occurs. It should accept one argument:

  • data (dict): A dictionary containing idx values for each volume.

The dictionary has a key ‘idx_values’, which is a list of dictionaries with the following keys:

  • id (str): The ID of the volume.

  • idx (float or None): The index of the cursor position for the volume.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

def hover_idx_callback(data):
    idx_values = data['idx_values']
    for idx_info in idx_values:
        volume_id = idx_info['id']
        idx = idx_info['idx']
        print(f'Volume ID: {volume_id}, Index: {idx}')

nv.on_hover_idx_change(hover_idx_callback)
on_image_loaded(callback, remove=False)[source]

Register a callback for the ‘image_loaded’ event.

Set a callback function to run when a new volume is loaded.

Parameters

callbackcallable

A function that takes one argument - a Volume object.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_image_loaded
def my_callback(volume):
    with out:
        print('Image loaded:', volume.id)
on_intensity_change(callback, remove=False)[source]

Register a callback for the ‘intensity_change’ event.

Set a callback function to run when the user changes the intensity range with the selection-box action (right click).

Parameters

callbackcallable

A function that takes one argument - a Volume object.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_intensity_change
def my_callback(volume):
    with out:
        print('Intensity changed for volume:', volume)
on_location_change(callback, remove=False)[source]

Register a callback for the ‘location_change’ event.

Set a callback function to run when the crosshair location changes.

Parameters

callbackcallable

A function that takes one argument - a dict containing the new location data - with the following keys:

  • ax_cor_sag (int): The view index where the location changed.

  • frac (list of float): The fractional coordinates [X, Y, Z]

    in the volume.

  • mm (list of float): The coordinates [X, Y, Z] in millimeters.

  • vox (list of int): The voxel coordinates [X, Y, Z].

  • values (list of float): Intensity values at the current location

    for each volume.

  • string (str): Formatted string representing the location and

    intensity values.

  • xy (list of float): The canvas coordinates [X, Y].

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_location_change
def my_callback(location):
    with out:
        print('Location changed', location)
on_mesh_added_from_url(callback, remove=False)[source]

Register a callback for the ‘mesh_added_from_url’ event.

Set a callback function to run when a mesh is added from a URL.

Note: This is called before the mesh_loaded event is emitted, so the mesh object will not be available in the callback.

Parameters

callbackcallable

A function that takes two arguments:

  • mesh_options (dict): Dictionary containing:
    • url (str): The URL from which the mesh was loaded.

    • headers (dict): HTTP headers used when loading the mesh.

  • mesh (dict): Dictionary containing:
    • id (str): The ID of the mesh.

    • name (str): The name of the mesh.

    • rgba255 (list of int): RGBA color values (0-255) of the mesh.

    • opacity (float): The opacity of the mesh.

    • visible (bool): Whether the mesh is visible.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_mesh_added_from_url
def my_callback(mesh_options, mesh):
    with out:
        print('Mesh added from URL')
        print('URL:', mesh_options['url'])
        print('Headers:', mesh_options['headers'])
        print('Mesh ID:', mesh['id'])
on_mesh_loaded(callback, remove=False)[source]

Register a callback for the ‘mesh_loaded’ event.

Set a callback function to run when a new mesh is loaded.

Parameters

callbackcallable

A function that takes one argument - the loaded mesh (Mesh object).

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_mesh_loaded
def my_callback(mesh):
    with out:
        print('Mesh loaded', mesh)
on_mouse_up(callback, remove=False)[source]

Register a callback for the ‘mouse_up’ event.

Set a callback function to run when the left mouse button is released.

Parameters

callbackcallable

A function that takes one argument - a dict containing mouse event data with the following keys:

  • is_dragging (bool): Indicates if a drag action is in progress

    (True) or not (False).

  • mouse_pos (tuple of int): The (x, y) pixel coordinates of the

    mouse on the canvas when the button was released.

  • frac_pos (tuple of float): The fractional position (X, Y, Z)

    within the volume, with each coordinate ranging from 0.0 to 1.0.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_mouse_up
def my_callback(data):
    with out:
        print('Mouse button released', data)
on_volume_added_from_url(callback, remove=False)[source]

Register a callback for the ‘volume_added_from_url’ event.

Set a callback function to run when a volume is added from a URL.

Note: This is called before the image_loaded event is emitted, so the volume object will not be available in the callback.

Parameters

callbackcallable

A function that takes two arguments:

  • image_options (dict): Dictionary containing:

    • url (str): The URL from which the volume was loaded.

    • url_image_data (str): The URL to the image data associated with

      the volume (if separate from header).

    • headers (dict): HTTP headers used when loading the volume.

    • name (str): A name for this image (default is an empty string).

    • colormap (str): A colormap to use (default is ‘gray’).

    • opacity (float): The opacity for this image (default is 1).

    • cal_min (float): Minimum intensity for color brightness/contrast.

    • cal_max (float): Maximum intensity for color brightness/contrast.

    • trust_cal_min_max (bool): Whether to trust cal_min and cal_max

      from the NIfTI header (default is True).

    • percentile_frac (float): The percentile to use for setting the

      robust range of the display values (default is 0.02).

    • use_qform_not_sform (bool): Whether to use QForm instead of SForm

      during construction (default is False).

    • alpha_threshold (bool): Whether to use alpha thresholding

      (default is False).

    • colormap_negative (str): Colormap for negative values.

    • cal_min_neg (float): Minimum intensity for negative color

      brightness/contrast.

    • cal_max_neg (float): Maximum intensity for negative color

      brightness/contrast.

    • colorbar_visible (bool): Visibility of the colorbar

      (default is True).

    • ignore_zero_voxels (bool): Whether to ignore zero voxels when

      setting the display range (default is False).

    • image_type (int): The image type (default is 0).

    • frame4D (int): Frame number for 4D images (default is 0).

    • colormap_label (str or None): Label for the colormap.

    • limit_frames4D (int): Limit the number of frames for 4D images.

    • is_manifest (bool): Whether the image is loaded from a manifest

      (default is False).

  • volume (dict): Dictionary containing:

    • id (str): The ID of the volume.

    • name (str): The name of the volume.

    • colormap (str): The colormap used for the volume.

    • opacity (float): The opacity of the volume.

    • colorbar_visible (bool): Visibility of the colorbar.

    • cal_min (float or None): Minimum calibration value.

    • cal_max (float or None): Maximum calibration value.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display
out = Output()
display(out)

@nv.on_volume_added_from_url
def my_callback(image_options, volume):
    with out:
        print('Volume added from URL')
        print('URL:', image_options['url'])
        print('Headers:', image_options['headers'])
        print('Volume ID:', volume['id'])
on_volume_updated(callback, remove=False)[source]

Register a callback for the ‘volume_updated’ event.

Sets a callback function to run when updateGLVolume is called. Most users will not need to use this directly.

Parameters

callbackcallable

A function that takes no arguments.

removebool, optional

If True, remove the callback. Defaults to False.

Examples

from ipywidgets import Output
from IPython.display import display

out = Output()
display(out)

@nv.on_volume_updated
def my_callback():
    with out:
        print('Volumes updated')
remove_haze(level: int = 5, vol_index: int = 0)[source]

Remove dark voxels in air.

Parameters

levelint, optional

Level of dehazing (1-5); larger values preserve more voxels. Default is 5.

vol_indexint, optional

Index of the volume to dehaze. Default is 0.

Examples

nv.remove_haze(3, 0)
save_document(file_name: str = 'document.nvd', compress: bool = True)[source]

Save the entire scene with settings as a document.

Parameters

file_namestr

The file name to save the document as.

compressbool

A value represneing if the file should be compressed.

Returns

None

Examples

nv.save_document("mydoc.nvd", False)
save_html(file_name: str = 'untitled.html', canvas_id: str = 'gl1')[source]

Save the current instance as an html page.

Parameters

file_namestr

The file name to save the page as.

canvas_idstr

The id of the canvas that NiiVue will be attached to.

Returns

None

Examples

nv.save_html("mypage.html")
save_image(file_name: str = 'image.nii.gz', save_drawing: bool = True, index_volume: int = 0)[source]

Save the current image as a nii file.

Parameters

file_namestr

The file name to save the image as.

save_drawingbool

A value representing if the drawings should be saved.

index_volumeint

The volume layer which should be saved (0 for background)

Returns

None

Examples

nv.save_image("myimage.nii.gz", True, 2)
save_scene(file_name: str = 'scene.png')[source]

Save the current scene with the provided file name.

Parameters

file_namestr

The file name to save the scene as.

Returns

None

Examples

nv.save_scene("myscene.png")
set_atlas_outline(outline: float)[source]

Set the outline thickness for atlas label regions.

Parameters

outlinefloat

The width of the outline to apply to atlas label regions. A value of 0 disables the outline.

Examples

nv.set_atlas_outline(2.0)
set_clip_plane(depth: float, azimuth: float, elevation: float)[source]

Update the clip plane orientation in 3D view mode.

Parameters

depthfloat

distance of clip plane from the center of the volume

azimuthfloat

camera position in degrees around the object

elevationfloat

camera height in degrees

Raises

TypeError

If any of the inputs are not a number.

Examples

nv.set_clip_plane(2.0, 42.0, 42.0)
set_colormap(imageID: str, colormap: str)[source]

Set the colormap for a volume.

Parameters

imageIDstr

The ID of the volume.

colormapstr

The name of the colormap to set.

Raises

ValueError

If the volume with the given ID is not found.

Examples

nv.set_colormap(nv.volumes[0].id, "green2cyan")
set_crosshair_color(color: tuple)[source]

Set the crosshair and colorbar outline color.

Parameters

colortuple of floats

An RGBA array with values ranging from 0 to 1.

Raises

ValueError

If the color is not a list of four numeric values.

Examples

nv.set_crosshair_color((0, 1, 0, 1))
set_crosshair_width(width: int)[source]

Set the crosshair width.

Parameters

widthint

The width of the crosshair in pixels.

Examples

nv.set_crosshair_width(3)
set_draw_colormap(colormap: str | ColorMap)[source]

Set colors and labels for different drawing values.

Parameters

colormapstr or ColorMap

A colormap name (string) or a ColorMap instance.

Examples

::
cmap = {

‘R’: [0, 255, 0], ‘G’: [0, 20, 0], ‘B’: [0, 20, 80], ‘A’: [0, 255, 255], ‘labels’: [‘’, ‘white-matter’, ‘delete T1’],

} nv.set_draw_colormap(cmap)

set_drawing_enabled(drawing_enabled: bool)[source]

Set/unset drawing state.

Parameters

drawing_enabled: bool

enabled or not

Examples

nv.set_drawing_enabled(True)
set_gamma(gamma: float = 1.0)[source]

Adjust screen gamma.

Parameters

gammafloat

Selects luminance

Raises

TypeError

If gamma is not a number

Examples

nv.set_gamma(3.0)
set_high_resolution_capable(force_device_pixel_ratio: int | bool)[source]

Force the rendering canvas to use a high-resolution display.

Parameters

force_device_pixel_ratioint or bool

Determines how the device pixel ratio is handled. True allows high DPI (equivalent to 0). False blocks high DPI (equivalent to -1).

Examples

nv.set_high_resolution_capable(True)
set_interpolation(is_nearest: bool)[source]

Select between nearest neighbor and linear interpolation for images.

Parameters

is_nearestbool

If True, use nearest neighbor interpolation. If False, use linear interpolation.

Examples

nv.set_interpolation(True)
set_mesh_layer_property(mesh_id: str, layer_index: int, attribute: str, value: Any)[source]

Set a property of a mesh layer.

Parameters

mesh_idstr

Identifier of the mesh to change (mesh id).

layer_indexint

The index of the layer within the mesh.

attributestr

The attribute to change.

valueAny

The value to set.

Raises

ValueError

If the attribute is not allowed or the mesh is not found.

IndexError

If the layer index is out of range.

Examples

nv.set_mesh_layer_property(nv.meshes[0].id, 0, 'opacity', 0.5)
set_mesh_property(mesh_id: str, attribute: str, value: Any)[source]

Set a property of a mesh.

Parameters

mesh_idstr

Identifier of the mesh to change (mesh id).

attributestr

The attribute to change.

valueAny

The value to set.

Raises

ValueError

If the attribute is not allowed or the mesh is not found.

Examples

nv.set_mesh_property(nv.meshes[0].id, 'opacity', 0.5)
set_mesh_shader(mesh_id: str, mesh_shader: str | int)[source]

Set the shader for a mesh.

Parameters

mesh_idstr

Identifier of the mesh to change (mesh id).

mesh_shaderstr or int

The name or index of the shader to set.

Raises

ValueError

If the mesh is not found. If the mesh shader is not found.

TypeError

If the mesh_shader is not a string nor integer.

Examples

nv.set_mesh_shader(nv.meshes[0].id, 'toon')
set_pen_value(pen_value: int, is_filled_pen: bool)[source]

Determine color and style of drawing.

Parameters

pen_valueint

sets the color of the pen

is_filled_penbool

determines if dragging creates flood-filled shape

Examples

nv.set_pen_value(1, True)
set_radiological_convention(is_radiological_convention: bool)[source]

Set radiological or neurological convention for 2D slices.

Parameters

is_radiological_conventionbool

If True, use radiological convention. If False, use neurological convention.

Examples

nv.set_radiological_convention(True)
set_render_azimuth_elevation(azimuth: float, elevation: float)[source]

Set the rotation of the 3D render view.

Parameters

azimuthfloat

The azimuth angle in degrees around the object.

elevationfloat

The elevation angle in degrees.

Raises

TypeError

If azimuth or elevation is not a number.

Examples

nv.set_render_azimuth_elevation(45, 15)
set_selection_box_color(color: tuple)[source]

Set the selection box color.

Parameters

colortuple of floats

An RGBA array with values ranging from 0 to 1.

Raises

ValueError

If the color is not a list of four numeric values.

Examples

nv.set_selection_box_color((0, 1, 0, 0.7))
set_slice_mm(is_slice_mm: bool)[source]

Control 2D slice view mode.

Parameters

is_slice_mmbool

Control whether 2D slices use world space (True) or voxel space (False).

Examples

nv.set_slice_mm(True)
set_slice_type(slice_type: SliceType)[source]

Set the type of slice display.

Parameters

slice_typeSliceType

The type of slice display.

Raises

TypeError

If slice_type is not a valid SliceType.

Examples

nv.set_slice_type(SliceType.AXIAL)
set_volume_render_illumination(gradient_amount: float)[source]

Set proportion of volume rendering influenced by selected matcap.

Parameters

gradient_amountfloat

Amount of matcap (NaN or 0..1). Default is 0.0 (matte, surface normal does not influence color). NaN renders the gradients.

Examples

nv.set_volume_render_illumination(0.6)
property volumes

Returns the list of volumes.

Returns

list

A list of dictionairies containing the volume information.

Examples

print(nv.volumes)
class ipyniivue.widget.Volume(**kwargs: Any)[source]

Bases: AnyWidget

Represents a Volume model.

Parameters

pathstr or pathlib.Path

Path to the volume data file; cannot be modified once set.

namestr, optional

Name of the volume.

opacityfloat, optional

Opacity between 0.0 (transparent) and 1.0 (opaque). Default is 1.0.

colormapstr, optional

Colormap name for rendering. Default is ‘gray’.

colorbar_visiblebool, optional

Show colorbar associated with the colormap. Default is True.

cal_minfloat or None, optional

Minimum intensity value for brightness/contrast mapping.

cal_maxfloat or None, optional

Maximum intensity value for brightness/contrast mapping.

frame4Dint, optional

Frame index for 4D volume data. Default is 0.

__init__(**kwargs)[source]

Public constructor

cal_max

A float trait.

cal_min

A float trait.

colorbar_visible

A boolean (True, False) trait.

colormap

A trait for unicode strings.

colormap_invert

A boolean (True, False) trait.

colormap_label

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

colormap_negative

A trait for unicode strings.

frame4D

An int trait.

id

A trait for unicode strings.

name

A trait for unicode strings.

opacity

A float trait.

path

A trait type representing a Union type.

set_colormap_label(colormap_data: dict)[source]

Set colormap label for the volume.

Parameters

colormap_datadict

The colormap dict data.

Colormaps contain the following keys (‘R’, ‘G’, ‘B’ are required):

  • R

  • G

  • B

  • A

  • I

  • min

  • max

  • labels

Examples

nv.volumes[0].set_colormap_label(colormap_data)
set_colormap_label_from_url(url)[source]

Set colormap label from a URL.

Parameters

urlstr

The colormap json url.

Examples

nv.volumes[0].set_colormap_label_from_url(url)
class ipyniivue.widget.Mesh(**kwargs: Any)[source]

Bases: AnyWidget

Represents a Mesh model.

Parameters

pathstr or pathlib.Path

Path to the mesh file. Cannot be modified once set.

namestr, optional

Name of the mesh.

rgba255list of int, optional

RGBA color as a list of four integers (0 to 255).

opacityfloat, optional

Opacity between 0.0 (transparent) and 1.0 (opaque). Default is 1.0.

visiblebool, optional

Mesh visibility. Default is True.

layerslist of dict, optional

List of layer data dictionaries. See MeshLayer for attribute options.

__init__(**kwargs)[source]

Public constructor

colorbar_visible

A boolean (True, False) trait.

colormap

A trait for unicode strings.

colormap_invert

A boolean (True, False) trait.

fiber_color

A trait for unicode strings.

fiber_decimation_stride

An int trait.

fiber_dither

A float trait.

fiber_length

A float trait.

fiber_radius

A float trait.

id

A trait for unicode strings.

layers

An instance of a Python list.

mesh_shader_index

An int trait.

name

A trait for unicode strings.

opacity

A float trait.

path

A trait type representing a Union type.

rgba255

An instance of a Python list.

visible

A boolean (True, False) trait.

class ipyniivue.widget.MeshLayer(**kwargs: Any)[source]

Bases: AnyWidget

Represents a layer within a Mesh model.

Parameters

pathstr or pathlib.Path

Path to the layer data file. Cannot be modified once set.

opacityfloat, optional

Opacity between 0.0 (transparent) and 1.0 (opaque). Default is 0.5.

colormapstr, optional

Colormap name for rendering. Default is ‘warm’.

colormap_negativestr, optional

Colormap for negative values if use_negative_cmap is True. Default is ‘winter’.

use_negative_cmapbool, optional

Use negative colormap for negative values. Default is False.

cal_minfloat or None, optional

Minimum intensity value for brightness/contrast mapping.

cal_maxfloat or None, optional

Maximum intensity value for brightness/contrast mapping.

outline_borderint, optional

Outline border thickness. Default is 0.

__init__(**kwargs)[source]

Public constructor

cal_max

A float trait.

cal_min

A float trait.

colorbar_visible

A boolean (True, False) trait.

colormap

A trait for unicode strings.

colormap_invert

A boolean (True, False) trait.

colormap_negative

A trait for unicode strings.

frame4D

An int trait.

id

A trait for unicode strings.

opacity

A float trait.

outline_border

An int trait.

path

A trait type representing a Union type.

use_negative_cmap

A boolean (True, False) trait.

class ipyniivue.traits.ColorMap(**kwargs: Any)[source]

Bases: HasTraits

Represents a ColorMap.

Parameters

Rlist of float

The red channel values.

Glist of float

The green channel values.

Blist of float

The blue channel values.

Alist of float or None, optional

The alpha (transparency) channel values. Default is None.

Ilist of float or None, optional

The intensity indices corresponding to the color values. Default is None.

minfloat or None, optional

The minimum intensity value for the colormap. Default is None.

maxfloat or None, optional

The maximum intensity value for the colormap. Default is None.

labelslist of str or None, optional

Labels associated with each color entry in the colormap. Default is None.

parentobject, optional

The parent object that contains this ColorMap. Used for propagating changes to the parent widget. Default is None.

A

An instance of a Python list.

B

An instance of a Python list.

G

An instance of a Python list.

I

An instance of a Python list.

R

An instance of a Python list.

__init__(*args, parent=None, **kwargs)[source]
labels

An instance of a Python list.

max

A float trait.

min

A float trait.

class ipyniivue.traits.LUT(**kwargs: Any)[source]

Bases: HasTraits

Represents a Lookup Table (LUT / Colormap Label).

Parameters

lutlist of int

A flat list representing the RGBA values of the lookup table.

minfloat or None, optional

The minimum intensity value corresponding to the first entry in the LUT. Default is None.

maxfloat or None, optional

The maximum intensity value corresponding to the last entry in the LUT. Default is None.

labelslist of str or None, optional

Labels associated with each color entry in the LUT. Default is None.

parentobject, optional

The parent object that contains this LUT. Used for propagating changes to the parent widget. Default is None.

__init__(*args, parent=None, **kwargs)[source]
labels

An instance of a Python list.

lut

An instance of a Python list.

max

A float trait.

min

A float trait.