annotations.local#

Functions for encoding or parsing data for local://annotations sources.

ngsidekick.annotations.local.extract_local_annotations(link, *, link_index=None, user=None, visible_only=False)[source]#

Extract local://annotations data from a neuroglancer link. The annotation coordinates (point, pointA, pointB, radii) are extracted into separate columns, named x,y,z/xa,ya,za/xb,yb,zb/rx,ry,rz (consistent with local_annotation_json() in this file).

Parameters:
  • link – Either a neuroglancer JSON state (dict), or a neuroglancer link with embedded state, or a neuroglancer link that references a JSON state file, such as https://neuroglancer-demo.appspot.com/#!gs://flyem-views/hemibrain/v1.2/base.json

  • link_index – Deprecated. Adds a column named ‘link_index’ populated with the provided value in all rows.

  • user – Deprecated. Adds a column named ‘user’ populated with the provided value in all rows.

  • visible_only – If True, do not extract annotations from layers that are not currently visible in the given link state.

Returns:

DataFrame

ngsidekick.annotations.local.local_annotation_json(df, name='annotations', color='#ffff00', size=8.0, linkedSegmentationLayer=None, show_panel=False, properties=[], shader=None, res_nm_xyz=(8, 8, 8))[source]#

Construct the JSON data for a neuroglancer local annotations layer. This does not result in a complete neuroglancer link; it results in something that can be added to the layers list in the neuroglancer viewer JSON state.

Note

This function’s signature will likely change in the future.

Parameters:
  • df

    DataFrame containing the annotation data. Which columns you must provide depends on which annotation type(s) you want to display.

    • For point annotations, provide [‘x’, ‘y’, ‘z’]

    • For line annotations or axis_aligned_bounding_box annotations, provide [‘xa’, ‘ya’, ‘za’, ‘xb’, ‘yb’, ‘zb’]

    • For ellipsoid annotations, provide [‘x’, ‘y’, ‘z’, ‘rx’, ‘ry’, ‘rz’] for the center point and radii.

    You may also provide a column ‘type’ to explicitly set the annotation type. In some cases, ‘type’ isn’t needed since annotation type can be inferred from the columns you provided. But in the case of line and box annotations, the input columns are the same, so you must provide a ‘type’ column.

    You may also provide additional columns to use as annotation properties, in which case they should be listed in the ‘properties’ argument. (See below.)

  • name – The name of the annotation layer

  • color – The default color for annotations, which can be overridden by the annotation shader.

  • size – The annotation size to hard-code into the default annotation shader used by this function. (Only used for points and line endpoints.)

  • linkedSegmentationLayer – If the annotations should be associated with another layer in the view, this specifies the name of that layer. This function sets the ‘filterBySegmentation’ key to hide annotations from non-selected segments. If you are providing a linkedSegmentationLayer, your dataframe should contain a ‘segments’ column to indicate which segments are associated with each annotation.

  • show_panel – If True, the selection panel will be visible in the side bar by default.

  • properties

    The list column names to use as annotation properties. Properties are visible in the selection panel when an annotation is selected, and they can also be used in annotation shaders via special functions neuroglancer defines for each property. For example, for a property named ‘confidence’, you could write setPointMarkerSize(prop_confidence()) in your annotation shader.

    This function supports annotation color proprties via strings (e.g. ‘#ffffff’) and also annotation ‘enum’ properties if you pass them via pandas categorical columns.

    By default, the annotation IDs are the same as the column names and the annotation types are inferred. You can override the property ‘spec’ by supplying a dict-of-dicts here instead of a list of columns:

    properties={
        "my_column": {
            "id": "my property",
            "description": "This is my annotation property.",
            "type": "float32",
            "enum_values": [0.0, 0.5, 1.0],
            "enum_labels": ["nothing", "something", "everything"],
        },
        "another_column: {...}
    }
    

Returns:

dict (JSON data)