Skip to content

statebuilder.skeletons

Classes:

SkeletonManager(segmentation_source, cloudpath, vertex_attributes=None, initialize_info=False, shader=None)

Create a manager to format and upload skeletons to a cloud bucket.

Parameters:

  • segmentation_source (Union[str, CAVEclient]) –

    The source of the segmentation data, either a string URL or a CAVEclient instance. If a CAVEclient instance is provided, the segmentation_source will be derived from it.

  • cloudpath (str) –

    The cloudpath where the skeletons will be stored. This is typically a gs:// or s3:// URL.

  • vertex_attributes (Optional[list[str]], default: None ) –

    An ordered list of vertex attribute names to be included in the skeletons, by default None. If None, no vertex attributes will be included.

  • initialize_info (bool, default: False ) –

    Whether to initialize the skeleton info in the cloud bucket if it does not exist, by default False. If False, an exception will be raised if the info file does not exist.

  • shader (Optional[str], default: None ) –

    A shader string to be used for rendering the skeletons in Neuroglancer, by default None.

Methods:

  • initialize_skeleton_info

    Initialize the skeleton info with the vertex attributes.

  • make_shader

    Create a shader for the skeletons based on the vertex attributes and other parameters.

  • to_segmentation_layer

    Generate a SegmentationLayer with the segmentation source and skeleton source, as well as uploaded segments and shader specified

  • upload_skeleton

    Upload a skeleton to the cloud bucket.

Attributes:

  • shader (str) –

    Return a skeleton shader with appropriate vertex properties and other attributes as set in make_shader.

  • skeleton_source (str) –

    Get the skeleton source URL for neuroglancer.

  • uploaded_root_ids (list[int]) –

    Get the set of root IDs that have been uploaded since the SkeletonManager was initialized.

  • vertex_attribute_names (list[str]) –

    The names of the vertex attributes in the skeletons.

  • vertex_attributes (dict) –

    The neuroglancer-formated vertex attribute dictionary for the skeletons.

shader property

Return a skeleton shader with appropriate vertex properties and other attributes as set in make_shader. If no shader is set, return a default shader that uses the vertex attributes defined in the SkeletonManager.

skeleton_source property

Get the skeleton source URL for neuroglancer.

uploaded_root_ids property

Get the set of root IDs that have been uploaded since the SkeletonManager was initialized.

vertex_attribute_names property

The names of the vertex attributes in the skeletons.

vertex_attributes property

The neuroglancer-formated vertex attribute dictionary for the skeletons.

initialize_skeleton_info()

Initialize the skeleton info with the vertex attributes.

make_shader(checkbox_controls=None, sliders=None, defined_colors=None, body=None)

Create a shader for the skeletons based on the vertex attributes and other parameters. The value will be stored in the shader property of the SkeletonManager instance.

Parameters:

  • checkbox_controls (Optional[dict], default: None ) –

    A dictionary of checkbox controls for the shader, by default None. Keys are the control names and values are booleans indicating whether the control is enabled by default. A pure list can also be provided, in which case all controls will be enabled by default.

  • sliders (Optional[dict], default: None ) –

    A dictionary or list of slider controls for the shader, by default None. Keys are the control names and values are tuples with the type (float or int), min, max, and default value. If provided as al list, all sliders will be set to float type with default range of 0 to 1 and value of 0.5.

  • defined_colors (Optional[dict], default: None ) –

    A dictionary of defined colors for the shader, by default None. Keys are the color variable names and values are tuples with hex or web color names. If provided as a list, sequential colors from the Tableau 10 colormap will be used.

  • body (Optional[str], default: None ) –

    Additional body code for the shader, by default None. This can be used to add custom shader logic or functions and should contain the emitRGB function. If None, a default body will be generated.

to_segmentation_layer(name='seg', uploaded_segments=True, segments_visible=True, shader=None)

Generate a SegmentationLayer with the segmentation source and skeleton source, as well as uploaded segments and shader specified

Parameters:

  • name (str, default: 'seg' ) –

    The name of the segmentation layer, by default "seg".

  • uploaded_segments (bool, default: True ) –

    Whether to include the uploaded segments in the layer, by default True. If True, the segments will be set to the uploaded root IDs with visibility set to segments_visible.

  • segments_visible (bool, default: True ) –

    Whether the uploaded segments should be visible in the layer, by default True.

  • shader (Optional[Union[bool, str]], default: None ) –

    A shader string to be used for the segmentation layer, by default None. If False, no shader will be applied. If None, the shader from the SkeletonManager will be used.

Returns:

  • SegmentationLayer

    A SegmentationLayer object with the specified parameters. This can be used in a ViewerState.add_layer method.

upload_skeleton(root_id, vertices, edges=None, vertex_attribute_data=None)

Upload a skeleton to the cloud bucket. Note that uploading the skeleton will add the root ID to the set of uploaded root IDs property.

Parameters:

  • root_id (int) –

    The root ID of the skeleton.

  • vertices (ndarray) –

    The vertices of the skeleton as a numpy array of shape (N, 3).

  • edges (Optional[ndarray], default: None ) –

    The edges of the skeleton as a numpy array of shape (M, 2), by default None. If None, an empty edge list will be created and the "skeleton" will be treated as a set of disconnected vertices.

  • vertex_attribute_data (Optional[Union[dict, DataFrame]], default: None ) –

    A dictionary or DataFrame containing vertex attribute data, where keys are attribute names and values are arrays of the same length as vertices. If any of the vertex attributes are not provided, they will default to zero arrays of the same length as vertices.