Skip to content

parser

Modules:

  • base
  • info

Classes:

Functions:

StateParser(state)

Convenience class for parsing neuroglancer states.

Parameters:

  • state (dict) –

    Neuroglancer state as a JSON dict

Methods:

  • annotation_dataframe

    Get a dataframe with all annotations across all annotation layers in the state.

  • layer_dataframe

    Get a dataframe with a row for each layer in the state.

  • selection_dataframe

    Get a dataframe with a row for each selected id across segmentation layers.

annotation_dataframe(expand_tags=False, point_resolution=None, split_points=False, include_archived=True)

Get a dataframe with all annotations across all annotation layers in the state.

Parameters:

  • expand_tags (bool, default: False ) –

    If True, expand tags into separate boolean columns named by the tag label. By default False. Note that if tag labels are duplicated in multiple layers, the values will appear in the same column.

  • point_resolution (Tuple[float, float, float], default: None ) –

    If provided, points will be rescaled to the provided x, y, z resolution (in nanometers). By default None.

  • split_points (bool, default: False ) –

    If True, points will be split into separate x, y, z columns. By default False.

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • DataFrame

    Dataframe with columns layer, anno_type, point, pointB, linked_segmentation, tags, anno_id, group_id, description. If expand_tags is True, an additional column will be added for each tag.

layer_dataframe(include_archived=True)

Get a dataframe with a row for each layer in the state.

Parameters:

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • DataFrame

    Dataframe with columns layer, type, source containing layer information.

selection_dataframe(include_archived=True)

Get a dataframe with a row for each selected id across segmentation layers.

Parameters:

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • DataFrame

    Dataframe with columns: layer, id, visible Visible only applies in Spelunker states.

annotation_dataframe(state, expand_tags=False, point_resolution=None, split_points=False, include_archived=True)

Return a dataframe with all annotations across all annotation layers in the state.

Parameters:

  • state (dict) –

    Neuroglancer state dictionary

  • expand_tags (bool, default: False ) –

    If True, expand tags into separate boolean columns named by the tag label. By default False. Note that if tag labels are duplicated in multiple layers, the values will appear in the same column.

  • point_resolution (Tuple[float, float, float], default: None ) –

    If provided, points will be rescaled to the provided x, y, z resolution (in nanometers). By default None.

  • split_points (bool, default: False ) –

    If True, points will be split into separate x, y, z columns. By default False.

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • DataFrame

    Dataframe with columns layer, anno_type, point, pointB, linked_segmentation, tags, anno_id, group_id, description. If expand_tags is True, an additional column will be added for each tag.

annotation_layers(state, include_archived=True)

Get all annotation layer names in the state

Parameters:

  • state (dict) –

    Neuroglancer state as a JSON dict

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • names ( list ) –

    List of layer names

bbox_annotations(state, layer_name, description=False, linked_segmentations=False, tags=False, group=False)

Get all bounding box annotation points and other info from a layer.

Parameters:

  • state (dict) –

    Neuroglancer state as JSON dict

  • layer_name (str) –

    Layer name

  • description (bool, default: False ) –

    If True, also returns descriptions as well. By default False

  • linked_segmentations (bool, default: False ) –

    If True, also returns list of linked segmentations, by default False

  • tags (bool, default: False ) –

    If True, also returns list of tags, by default False

Returns:

  • anno_points_A ( list ) –

    List of N 3-element points (as list) of the first point in each bbox.

  • anno_points_B ( list ) –

    List of N 3-element points (as list) of the second point in each bbox.

  • anno_descriptions ( list ) –

    List of N strings (or None), only returned if description=True.

  • anno_linked_segmentations ( list ) –

    List of N lists of object ids. Only returned if linked_segmentations=True.

  • anno_tags ( list ) –

    List of N lists of tag ids. Only returned if tags=True.

  • anno_group ( list ) –

    List of group ids (as string) or None for annotations. Only returned if group=True

extract_multicut(state, seg_layer=None)

Extract information entered into the multicut graph operation

Parameters:

  • state (dict) –

    Neuroglancer state

  • seg_layer (str, default: None ) –

    Name of a segmentation layer or None. If None, the function will check how many segmentation layers there are and, if only one exits, choose it. If more than one segmentation layer is present, it errors. By default None

Returns:

  • pts ( array ) –

    Nx3 array of points selected

  • side ( array ) –

    N array with 'source' or 'sink', depending on which side the point is on.

  • svids ( array ) –

    N array with selected supervoxel. If only points are selected (e.g. via clicking on the mesh), the value will be NaN.

  • root_id ( int ) –

    Root id of the object to split

get_layer(state, layer_name)

Gets the contents of the layer based on the layer name.

Parameters:

  • state (dict) –

    Neuroglancer state as a JSON dict

  • layer_name (str) –

    Name of layer

Returns:

  • layer ( dict ) –

    Layer data contents

get_selected_ids(state, layer=None, return_nonvisible=False)

Get a list of selected ids in a segmentation layer

Parameters:

  • state (dict) –

    State dict

  • layer (str, default: None ) –

    Segmentation layer name, if needed. If None and only one segmentation layer is present, default to it. By default None

  • return_nonvisible (bool, default: False ) –

    If True, also return non-visible ids. By default False

Returns:

  • list

    List of root ids.

group_annotations(state, layer_name, description=False, linked_segmentations=False, tags=False)

All group annotations and their associated points

Parameters:

  • state (dict) –

    Neuroglancer state as JSON dict

  • layer_name (str) –

    Annotation layer name

  • description (bool, default: False ) –

    If True, also returns descriptions as well. By default False

  • linked_segmentations (bool, default: False ) –

    If True, also returns list of linked segmentations, by default False

  • tags (bool, default: False ) –

    If True, also returns list of tags, by default False

Returns:

  • group_points ( list ) –

    List of N 3-element points

  • group_id ( list ) –

    List of N id strings for groups.

  • anno_descriptions ( list ) –

    List of N strings (or None), only returned if description=True.

  • anno_linked_segmentations ( list ) –

    List of N lists of object ids. Only returned if linked_segmentations=True.

  • anno_tags ( list ) –

    List of N lists of tag ids. Only returned if tags=True.

image_layers(state, include_archived=True)

Get all image layer names in the state

Parameters:

  • state (dict) –

    Neuroglancer state as a JSON dict

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • names ( list ) –

    List of layer names

layer_dataframe(state, include_archived=True)

Return a dataframe with a row for each layer in the state.

Parameters:

  • state (dict) –

    Neuroglancer state

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • DataFrame

    Dataframe with columns layer, type, source

layer_names(state, include_archived=True)

Get all layer names in the state

Parameters:

  • state (dict) –

    Neuroglancer state as a JSON dict

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • names ( list ) –

    List of layer names

layer_source(state, layer_name)

Get url source or list of sources for a layer

Parameters:

  • state (dict) –

    Neuroglancer state as a JSON dict

  • layer_name (str) –

    Name of layer

Returns:

  • str

    URL source or list of URL sources

line_annotations(state, layer_name, description=False, linked_segmentations=False, tags=False, group=False)

Get all line annotation points and other info from a layer.

Parameters:

  • state (dict) –

    Neuroglancer state as JSON dict

  • layer_name (str) –

    Layer name

  • description (bool, default: False ) –

    If True, also returns descriptions as well. By default False

  • linked_segmentations (bool, default: False ) –

    If True, also returns list of linked segmentations, by default False

  • tags (bool, default: False ) –

    If True, also returns list of tags, by default False

Returns:

  • anno_points_A ( list ) –

    List of N 3-element points (as list) of the first point in each line.

  • anno_points_B ( list ) –

    List of N 3-element points (as list) of the second point in each line.

  • anno_descriptions ( list ) –

    List of N strings (or None), only returned if description=True.

  • anno_linked_segmentations ( list ) –

    List of N lists of object ids. Only returned if linked_segmentations=True.

  • anno_tags ( list ) –

    List of N lists of tag ids. Only returned if tags=True.

  • anno_group ( list ) –

    List of group ids (as string) or None for annotations. Only returned if group=True

point_annotations(state, layer_name, description=False, linked_segmentations=False, tags=False, group=False)

Get all point annotation points and other info from a layer.

Parameters:

  • state (dict) –

    Neuroglancer state as JSON dict

  • layer_name (str) –

    Layer name

  • description (bool, default: False ) –

    If True, also returns descriptions as well. By default False

  • linked_segmentations (bool, default: False ) –

    If True, also returns list of linked segmentations, by default False

  • tags (bool, default: False ) –

    If True, also returns list of tags, by default False

Returns:

  • anno_points ( list ) –

    List of N 3-element points (as list)

  • anno_descriptions ( list ) –

    List of N strings (or None), only returned if description=True.

  • anno_linked_segmentations ( list ) –

    List of N lists of object ids. Only returned if linked_segmentations=True.

  • anno_tags ( list ) –

    List of N lists of tag ids. Only returned if tags=True.

  • anno_group ( list ) –

    List of group ids (as string) or None for annotations. Only returned if group=True

segmentation_layers(state, include_archived=True)

Get all segmentation layer names in the state

Parameters:

  • state (dict) –

    Neuroglancer state as a JSON dict

Returns:

  • names ( list ) –

    List of layer names

selection_dataframe(state, include_archived=True)

Return a dataframe with a row for each selected id across segmentation layers.

Parameters:

  • state (dict) –

    Neuroglancer state

  • include_archived (bool, default: True ) –

    If True, include archived layers. By default True

Returns:

  • DataFrame

    Dataframe with columns: layer, id, visible Visible only applies in Spelunker states.

sphere_annotations(state, layer_name, description=False, linked_segmentations=False, tags=False, group=False)

Get all sphere annotation points and other info from a layer.

Parameters:

  • state (dict) –

    Neuroglancer state as JSON dict

  • layer_name (str) –

    Layer name

  • description (bool, default: False ) –

    If True, also returns descriptions as well. By default False

  • linked_segmentations (bool, default: False ) –

    If True, also returns list of linked segmentations, by default False

  • tags (bool, default: False ) –

    If True, also returns list of tags, by default False

Returns:

  • anno_points ( list ) –

    List of N 3-element center points (as list)

  • radius_points ( list ) –

    List of N 3-element radii for each axis of the ellipsoid.

  • anno_descriptions ( list ) –

    List of N strings (or None), only returned if description=True.

  • anno_linked_segmentations ( list ) –

    List of N lists of object ids. Only returned if linked_segmentations=True.

  • anno_tags ( list ) –

    List of N lists of tag ids. Only returned if tags=True.

  • anno_group ( list ) –

    List of group ids (as string) or None for annotations. Only returned if group=True

tag_dictionary(state, layer_name)

Get the tag id to string dictionary for a layer

Parameters:

  • state (dict) –
  • layer_name ([type]) –

    [description]

Returns:

  • [type]

    [description]

view_settings(state)

Get all data about the view state in neuroglancer: position, image zoom, orientation and zoom of the 3d view, and voxel size.

Parameters:

  • state (dict) –

    Neuroglancer state as JSON dict

Returns:

  • view ( dict ) –

    Dictionary with keys: position, zoomFactor, perspectiveOrientation, perspectiveZoom, and voxelSize