statebuilder
Classes:
-
ChainedStateBuilder
–Builds a collection of states that sequentially add annotations based on a sequence of dataframes.
-
StateBuilder
–A class for schematic mapping data frames into neuroglancer states.
ChainedStateBuilder(statebuilders)
Builds a collection of states that sequentially add annotations based on a sequence of dataframes.
Parameters:
-
statebuilders
(list
) –List of DataStateBuilders, in same order as dataframes will be passed
Methods:
-
render_state
–Generate a single neuroglancer state by addatively applying an ordered collection of
render_state(data_list=None, base_state=None, return_as='url', url_prefix=None, link_text='Neuroglancer Link', target_site=None, client=None)
Generate a single neuroglancer state by addatively applying an ordered collection of dataframes to an collection of StateBuilder renders. Parameters data_list : Collection of DataFrame. The order must match the order of StateBuilders contained in the class on creation. base_state : JSON neuroglancer state (optional, default is None). Used as a base state for adding everything else to. return_as: ['url', 'viewer', 'html', 'json', 'short']. optional, default='url'. Sets how the state is returned. Note that if a viewer is returned, the state is not reset to default. url_prefix: string, optional (default is https://neuromancer-seung-import.appspot.com). Overrides the default neuroglancer url for url generation. link_text: string, optional (default is 'Neuroglancer Link'). Text to use for the link when returning as html. target_site: string, optional (default is None). Target Neuroglancer category: either "seunglab" or "mainline"/"cave-explorer"/"spelunker". Will be looked up automatically based on url_prefix, if used. client: caveclient.CAVEclient, optional (default is None). A caveclient to get defaults from. Defaults to None, which falls back on the last statebuilder.
StateBuilder(layers=[], base_state=None, url_prefix=None, state_server=None, resolution=None, view_kws={}, client=None, target_site=None)
A class for schematic mapping data frames into neuroglancer states.
Parameters:
-
layers
(list of nglui.statebuilder.layers.LayerConfigBase
, default:[]
) –List of layers to add. Defaults to [].
-
base_state
(dict
, default:None
) –JSON state to add to. Defaults to None.
-
url_prefix
(str
, default:None
) –http(s) path to Neuroglancer deployment to use. Defaults to None, which will use https://neuromancer-seung-import.appspot.com
-
state_server
(str
, default:None
) –State server to post links to. Defaults to None.
-
resolution
(list of float
, default:None
) –3-element vector controlling the viewer resolution. Defaults to None. If None and a client is set, uses the client viewer resolution.
-
view_kws
(dict
, default:{}
) –Dictionary controlling view parameters. Defaults to {}.
Keys are: show_slices : bool, optional Sets if slices are shown in the 3d view. Defaults to False. layout : str, optional
xy-3d
/xz-3d
/yz-3d
(sections plus 3d pane),xy
/yz
/xz
/3d
(only one pane), or4panel
(all panes). Default isxy-3d
. show_axis_lines : bool, optional Determines if the axis lines are shown in the middle of each view. show_scale_bar : bool, optional Toggles showing the scale bar. orthographic : bool, optional Toggles orthographic view in the 3d pane. position : list of float, optional (length-3) Determines the centered location. zoom_image : float, optional Zoom level for the imagery in units of nm per voxel. Defaults to 8. zoom_3d : float, optional Zoom level for the 3d pane. Defaults to 2000. Smaller numbers are more zoomed in. background_color : str or list of float, optional Sets the background color of the 3d view. Arguments can be rgb values, hex colors, or named web colors. Defaults to black. -
client
(CAVEclient
, default:None
) –A caveclient to get defaults from. Defaults to None.
-
target_site
(str
, default:None
) –Target Neuroglancer category: either "seunglab" or "mainline"/"cave-explorer"/"spelunker". Defaults to None. Will be looked up automatically based on ngl_url, if used.
Methods:
-
initialize_state
–Generate a new Neuroglancer state with layers as needed for the schema.
-
render_state
–Build a Neuroglancer state out of a DataFrame.
initialize_state(base_state=None, target_site=None)
Generate a new Neuroglancer state with layers as needed for the schema.
Parameters:
-
base_state
(str
, default:None
) –Optional initial state to build on, described by its JSON. By default None.
render_state(data=None, base_state=None, return_as='url', url_prefix=None, link_text='Neuroglancer Link', target_site=None, client=None)
Build a Neuroglancer state out of a DataFrame.
Parameters:
-
data
(DataFrame
, default:None
) –DataFrame to use as a point source. By default None, for which it will return only the base_state and any fixed values.
-
base_state
(dict
, default:None
) –Initial state to build on, expressed as Neuroglancer JSON. By default None
-
return_as
(['url', 'viewer', 'html', 'json', 'dict', 'short']
, default:'url'
) –Choice of output types. Note that if a viewer is returned, the state is not reset. url : Returns the raw url describing the state viewer : Returns an EasyViewer object holding the state information html : Returns an HTML link to the url, useful for notebooks. json : Returns a JSON string describing the state. dict : Returns a dict version of the JSON state. short : Posts the state to the state server and returns a short link. Requires a client. By default 'url'
-
url_prefix
(str
, default:None
) –Neuroglancer URL prefix to use. By default None, for which it will open with the class default.
-
link_text
(str
, default:'Neuroglancer Link'
) –Text to use for the link when returning as html, by default 'Neuroglancer Link'
-
target_site
(str
, default:None
) –Target Neuroglancer category: either "seunglab" or one of "mainline"/"cave-explorer"/"spelunker". Defaults to None. Will be looked up automatically based on ngl_url, if used and a client is set.
-
client
(CAVEclient
, default:None
) –A caveclient to get defaults from. Defaults to None, which falls back on the statebuilder.
Returns:
-
string or Viewer
–A link to or viewer for a Neuroglancer state with layers, annotations, and selected objects determined by the data.
Classes:
-
AnnotationLayerConfig
–Configuration class for annotation layers
-
ImageLayerConfig
–Image layer configuration class.
-
LayerConfigBase
–Base class for configuring layers
-
SegmentationLayerConfig
–Configuration class for segmentation layers
AnnotationLayerConfig(name=None, color=None, linked_segmentation_layer=None, mapping_rules=[], array_data=False, tags=None, active=True, filter_by_segmentation=False, brackets_show_segmentation=True, selection_shows_segmentation=True, filter_query=None, data_resolution=None)
Bases: LayerConfigBase
Configuration class for annotation layers
Parameters:
-
name
(str
, default:None
) –Layer name. By default, 'annos'
-
color
(str
, default:None
) –Hex color code with an initial #. By default, None
-
linked_segmentation_layer
(str
, default:None
) –Name of a linked segmentation layer for selected ids. By default, None
-
mapping_rules
((PointMapper, LineMapper, SphereMapper or list)
, default:[]
) –One rule or a list of rules mapping data to annotations. By default, []
-
array_data
(bool
, default:False
) –If True, allows simple mapping where one or more arrays are passed instead of a dataframe. Only allows basic annotation creation, no tags, linked segmentations, or other rich features.
-
tags
(list
, default:None
) –List of tags for the layer.
-
active
(bool
, default:True
) –If True, makes the layer selected. Default is True (unlike for image/segmentation layers).
ImageLayerConfig(source, name=None, active=False, contrast_controls=False, black=0.0, white=1.0)
Bases: LayerConfigBase
Image layer configuration class.
This provides the rules for setting up an image layer in neuroglancer.
Parameters:
-
source
(str
) –Cloudpath to an image source
-
name
(str
, default:None
) –Name of the image layer. By default, 'img'.
-
active
(bool
, default:False
) –If True, makes the layer active in neuroglancer. Default is False.
-
contrast_controls
(bool
, default:False
) –If True, gives the layer a user-controllable brightness and contrast shader. Default is False.
-
black
(float
, default:0.0
) –If contrast_controls is True, sets the default black level. Default is 0.0.
-
white
(float
, default:1.0
) –If contrast_controls is True, sets the default white level. Default is 1.0.
LayerConfigBase(name, type, source, color, active)
SegmentationLayerConfig(source, name=None, selected_ids_column=None, fixed_ids=None, fixed_id_colors=None, color_column=None, active=False, alpha_selected=0.3, alpha_3d=1, alpha_unselected=0, split_point_map=None, view_kws=None, timestamp=None, data_resolution=None, mapping_set=None, segment_properties=None, skeleton_source=None, skeleton_shader=None)
Bases: LayerConfigBase
Configuration class for segmentation layers
Parameters:
-
source
(str
) –Segmentation source
-
name
((str, optional)
, default:None
) –Layer name.
-
selected_ids_column
(str or list-like, optional.
, default:None
) –Column name (or list of column names) to use for selected ids.
-
fixed_ids
(list-like, optional.
, default:None
) –List of root ids to select directly.
-
fixed_id_colors
(list-like, optional.
, default:None
) –List of colors for fixed ids. Should be the same length as fixed_ids, although null entries can be padded with None values.
-
color_column
(str, optional.
, default:None
) –at the begining.
Column to use for color values for selected objects. Values should be RGB hex strings with a
-
active
(bool, optional.
, default:False
) –If True, makes the layer selected. Default is False.
-
alpha_selected
–Opacity of selected segmentations in the image layer. Optional, default is 0.3.
-
alpha_3d
–Opacity of meshes. Optional, default is 1.
-
alpha_unselected
–Opacity of unselected segments. Optional, default is 0.
-
split_point_map
–If not None, provides an object to map the dataframe input to multicut points. Default is None.
-
view_kws
(dict, optional.
, default:None
) –Keyword arguments for viewer.set_segmentation_view_options. Sets selected (and unselected) segmetation alpha values. Defaults to values in DEFAULT_SEGMENTATION_VIEW_KWS dict specified in this module.
-
timestamp
(float or datetime, optional.
, default:None
) –Timestamp at which to fix the chunkedgraph in either unix epoch or datetime format. Optional, default is None.
-
mapping_set
(str, optional.
, default:None
) –Name of the mapping set, the key in the data dictionary for statebuilder. Optional, default is None.
-
segment_properties
–Location of a segment properties file. Optional, default is None.
-
skeleton_source
–Location of a skeleton source. Optional, default is None.
-
skeleton_shader
–Shader function for rendering skeletons, if set with
skeleton_source
. Optional, default is None.
Methods:
-
add_selection_map
–Add rules for selecting active segment ids and their colors
add_selection_map(selected_ids_column=None, fixed_ids=None, fixed_id_colors=None, color_column=None, mapping_set=None)
Add rules for selecting active segment ids and their colors
Parameters:
-
selected_ids_column
(str
, default:None
) –Dataframe column to use for adding selected segment ids to the segmentation layer, by default None
-
fixed_ids
(int or list
, default:None
) –Add one or more segment ids to be active, independent of the data, by default None
-
fixed_id_colors
(list
, default:None
) –Add a list of colors (hex, rgb, or CSS3 string) to assign to the fixed ids, by default None
-
color_column
(str
, default:None
) –Dataframe column to use for adding selected segment colors, by default None
-
mapping_set
(str
, default:None
) –Name of the mapping set, the key in the data dictionary for statebuilder, by default None
Modules:
-
ev_base
–
Classes:
-
BoundingBoxMapper
–Sets rules to map dataframes to bounding box annotations
-
LineMapper
–Sets rules to map dataframes to line annotations
-
PointMapper
–Sets rules to map dataframes to point annotations
-
SelectionMapper
–Class for configuring object selections based on root id
-
SphereMapper
–Sets rules to map dataframes to sphere annotations
-
SplitPointMapper
–Mapper to create split points in a segmentation layer.
BoundingBoxMapper(point_column_a=None, point_column_b=None, description_column=None, linked_segmentation_column=None, tag_column=None, group_column=None, gather_linked_segmentations=True, share_linked_segmentations=False, set_position=True, multipoint=False, collapse_groups=False, split_positions=False, mapping_set=None)
Bases: AnnotationMapperBase
Sets rules to map dataframes to bounding box annotations
Parameters:
-
point_column_a
(str
, default:None
) –Column name with 3d position data for the first point of the bounding box. Must be set if array_data is False (the default)
-
point_column_b
(str
, default:None
) –Column name with 3d position data for the second point of the bounding box. Must be set if array_data is False (the default)
-
description_column
(str
, default:None
) –Column name with string data for annotation descriptions
-
linked_segmentation_column
(str
, default:None
) –Column name for root ids to link to annotations
-
tag_column
(str
, default:None
) –Column name for categorical tag data. Tags must match those set in the annotation layer.
-
group_column
(str
, default:None
) –Column name for grouping data. Data in this row should be numeric with possible NaNs. Rows with the same non-NaN value will be collected into a grouped annotation.
-
set_position
(bool
, default:True
) –If set to True, moves the position to center on the first point in the data (using point_column_a).
-
multipoint
–If True, permits multiple points in a given row, sharing data in other columns. Each point row must have the same number of points. Default is False.
-
collapse_groups
–If True, groups are toggled closed in the annotation view.
-
mapping_set
–If set, assumes data is passed as a dictionary and uses this string to as the key for the data to use.
LineMapper(point_column_a=None, point_column_b=None, description_column=None, linked_segmentation_column=None, tag_column=None, group_column=None, gather_linked_segmentations=True, share_linked_segmentations=False, set_position=True, multipoint=False, collapse_groups=False, split_positions=False, mapping_set=None)
Bases: AnnotationMapperBase
Sets rules to map dataframes to line annotations
Parameters:
-
point_column_a
(str
, default:None
) –Column name with 3d position data for the first point of the line. Must be set if array_data is False (the default)
-
point_column_b
(str
, default:None
) –Column name with 3d position data for the first point of the line. Must be set if array_data is False (the default)
-
description_column
(str
, default:None
) –Column name with string data for annotation descriptions
-
linked_segmentation_column
(str
, default:None
) –Column name for root ids to link to annotations
-
tag_column
(str
, default:None
) –Column name for categorical tag data. Tags must match those set in the annotation layer.
-
group_column
(str
, default:None
) –Column name for grouping data. Data in this row should be numeric with possible NaNs. Rows with the same non-NaN value will be collected into a grouped annotation.
-
set_position
(bool
, default:True
) –If set to True, moves the position to center on the first point in the data (using point_column_a).
-
multipoint
–If True, permits multiple points in a given row, sharing data in other columns. Each point row must have the same number of points. Default is False.
-
collapse_groups
–If True, groups are toggled closed in the annotation view.
-
mapping_set
–If set, assumes data is passed as a dictionary and uses this string to as the key for the data to use.
PointMapper(point_column=None, description_column=None, linked_segmentation_column=None, tag_column=None, group_column=None, gather_linked_segmentations=True, share_linked_segmentations=False, set_position=True, multipoint=False, collapse_groups=False, split_positions=False, mapping_set=None)
Bases: AnnotationMapperBase
Sets rules to map dataframes to point annotations
Parameters:
-
point_column
(str
, default:None
) –Column name with 3d position data
-
description_column
(str
, default:None
) –Column name with string data for annotation descriptions
-
linked_segmentation_column
(str
, default:None
) –Column name for root ids to link to annotations
-
tag_column
(str
, default:None
) –Column name for categorical tag data. Tags must match those set in the annotation layer.
-
group_column
(str
, default:None
) –Column name for grouping data. Data in this row should be numeric with possible NaNs. Rows with the same non-NaN value will be collected into a grouped annotation.
-
set_position
(bool
, default:True
) –If set to True, moves the position to center on the first point in the data.
-
multipoint
–If True, permits multiple points in a given row, sharing data in other columns. Default is False.
-
collapse_groups
–If True, groups are toggled closed in the annotation view.
-
mapping_set
–If given, assumes data is passed as a dictionary and uses this string to as the key for the data to use.
SelectionMapper(data_columns=None, fixed_ids=None, fixed_id_colors=None, color_column=None, mapping_set=None)
Class for configuring object selections based on root id
Parameters:
-
data_columns
(str or list
, default:None
) –Name (or list of names) of the data columns to get ids from. Default is None.
-
fixed_ids
(list
, default:None
) –List of ids to select irrespective of data.
-
fixed_id_colors
(list
, default:None
) –List of colors associated with the fixed ids list.
-
color_column
(str
, default:None
) –Column name with color data per row
-
mapping_set
(str
, default:None
) –If set, assumes data is passed as a dictionary and uses this string to as the key for the data to use. Note that using a mapping_set for one Mapper requires all Mappers use them. You cannot mix and match specificed mapping sets and ordered lists.
Methods:
-
selected_ids
–Uses the rules to generate a list of ids from a dataframe.
selected_ids(data)
Uses the rules to generate a list of ids from a dataframe.
SphereMapper(center_column=None, radius_column=None, description_column=None, linked_segmentation_column=None, tag_column=None, group_column=None, gather_linked_segmentations=True, share_linked_segmentations=False, z_multiplier=0.1, set_position=True, multipoint=False, collapse_groups=False, split_positions=False, mapping_set=None)
Bases: AnnotationMapperBase
Sets rules to map dataframes to sphere annotations
Parameters:
-
center_column
(str
, default:None
) –Column name with 3d position data for the center of the sphere
-
radius_column
(str
, default:None
) –Column name with a radius for the sphere (in nm)
-
description_column
(str
, default:None
) –Column name with string data for annotation descriptions
-
linked_segmentation_column
(str
, default:None
) –Column name for root ids to link to annotations
-
tag_column
(str
, default:None
) –Column name for categorical tag data. Tags must match those set in the annotation layer.
-
group_column
(str
, default:None
) –Column name for grouping data. Data in this row should be numeric with possible NaNs. Rows with the same non-NaN value will be collected into a grouped annotation.
-
set_position
(bool
, default:True
) –If set to True, moves the position to center on the first point in the data.
-
multipoint
–If True, permits multiple points in a given row, sharing data in other columns. Each point row must have the same number of points. Default is False.
-
collapse_groups
–If True, groups are toggled closed in the annotation view.
-
mapping_set
–If set, assumes data is passed as a dictionary and uses this string to as the key for the data to use.
SplitPointMapper(id_column, point_column, team_column, team_names=['red', 'blue'], supervoxel_column=None, focus=True, mapping_set=None)
Mapper to create split points in a segmentation layer.
Parameters:
-
id_column
(str
) –Column name for segment ids. The id column must contain the same id in all rows.
-
point_column
(str
) –Name of the column containing points in space.
-
team_column
(str
) –Name of the column describing the team for the points. The contents of the column should have two values, by default "red" and "blue".
-
team_names
(list
, default:['red', 'blue']
) –List of two values for the team names used in the team column. The first is mapped to red points, the second blue. Default is ["red", "blue"].
-
supervoxel_column
(str or None
, default:None
) –Name of a column providing supervoxel ids. If None (default), the supervoxel must be looked up on the server.
-
focus
(bool
, default:True
) –If True, sets the focus on the split tool and sets the position to the center of split points. Default is True.
Returns:
-
SplitPointMapper instance to pass to a segmentation layer.
–
.helpers
Functions:
-
from_client
–Generate basic image and segmentation layers from a FrameworkClient
-
make_line_statebuilder
–Generate a state builder that puts points on a single column with a linked segmentaton id
-
make_neuron_neuroglancer_link
–function to create a neuroglancer link view of a neuron, optionally including inputs and outputs
-
make_point_statebuilder
–Generate a state builder that puts points on a single column with a linked segmentaton id
-
make_pre_post_statebuilder
–Function to generate ChainedStateBuilder with optional pre and post synaptic
-
make_state_url
–Generate a url from a neuroglancer state via a state server.
-
make_synapse_neuroglancer_link
–Generate a neuroglancer link from a synapse dataframe as returned from CAVEclient.materialize.synapse_query.
-
make_url_robust
–Generate a url from a neuroglancer state. If too long, return through state server,
-
package_state
–Automate creating a state from a statebuilder and
-
segment_property_link
–Returns a basic link to a default neuroglancer state and segment properties.
-
sort_dataframe_by_root_id
–Sort a dataframe so that rows belonging to the same root id are together, ordered by how many times the root id appears.
from_client(client, image_name=None, segmentation_name=None, contrast=None, use_skeleton_service=False)
Generate basic image and segmentation layers from a FrameworkClient
Parameters:
-
client
(CAVEclient
) –A CAVEclient with a specified datastack
-
image_name
(str
, default:None
) –Name for the image layer, by default None.
-
segmentation_name
(str
, default:None
) –Name for the segmentation layer, by default None
-
contrast
(list - like or False
, default:None
) –Two elements specifying the black level and white level as floats between 0 and 1, by default None. If None, no contrast is set.
-
use_skeleton_service
(bool
, default:False
) –If True, uses a skeleton service, if advertised, with the segmentation. Defaults to False.
Returns:
-
image_layer
(ImageLayerConfig
) –Image layer with default values from the client
-
seg_layer
(ImageLayerConfig
) –Segmentation layer with default values from the client
make_line_statebuilder(client, point_column_a='pre_pt_position', point_column_b='post_pt_position', linked_seg_column='pt_root_id', description_column=None, tag_column=None, data_resolution=None, group_column=None, contrast=None, view_kws=None, point_layer_name='lines', color=None, split_positions=False)
Generate a state builder that puts points on a single column with a linked segmentaton id
Parameters:
-
client
(CAVEclient
) –CAVEclient configured for the datastack desired
-
point_column_a
(str
, default:'pre_pt_position'
) –column in dataframe to pull points from. Defaults to "pre_pt_position".
-
point_column_b
(str
, default:'post_pt_position'
) –column in dataframe to pull points from. Defaults to "post_pt_position".
-
linked_seg_column
(str
, default:'pt_root_id'
) –column to link to segmentation, None for no column. Defaults to "pt_root_id".
-
group_column
(str, or list
, default:None
) –column(s) to group annotations by, None for no grouping (default=None)
-
tag_column
(str
, default:None
) –column to use for tags, None for no tags (default=None)
-
description_column
(str
, default:None
) –column to use for descriptions, None for no descriptions (default=None)
-
contrast
(list
, default:None
) –Two elements specifying the black level and white level as floats between 0 and 1, by default None. If None, no contrast is set.
-
view_kws
(dict
, default:None
) –dictionary of view keywords to configure neuroglancer view
-
split_positions
(bool
, default:False
) –whether the position column into x,y,z columns. Defaults to False.
Returns:
-
StateBuilder
–A statebuilder to make points with linked segmentations
make_neuron_neuroglancer_link(client, root_ids, return_as='html', shorten='always', show_inputs=False, show_outputs=False, sort_inputs=True, sort_outputs=True, sort_ascending=False, input_color=DEFAULT_POSTSYN_COLOR, output_color=DEFAULT_PRESYN_COLOR, contrast=None, timestamp=None, view_kws=None, point_column='ctr_pt_position', pre_pt_root_id_col='pre_pt_root_id', post_pt_root_id_col='post_pt_root_id', input_layer_name='syns_in', output_layer_name='syns_out', ngl_url=None, link_text='Neuroglancer Link', target_site=None)
function to create a neuroglancer link view of a neuron, optionally including inputs and outputs
Parameters:
-
client
(CAVEclient
) –A CAVEclient configured for the datastack to visualize.
-
root_ids
(Iterable[int]
) –The root_ids to build the visualization around.
-
return_as
(str
, default:'html'
) –How to return the URL or state. Valid options are: - 'html': Returns an IPython HTML element. - 'json': Returns a dictionary representing the Neuroglancer state. - 'url': Returns a URL string. Defaults to 'html'.
-
shorten
(str
, default:'always'
) –Whether to shorten the link. Valid options are: - 'always': Always shorten the link. - 'if_long': Shorten the link if it exceeds MAX_URL_LENGTH. - 'never': Never shorten the link. Defaults to 'if_long'.
-
show_inputs
(bool
, default:False
) –Whether to include input synapses. Defaults to False.
-
show_outputs
(bool
, default:False
) –Whether to include output synapses. Defaults to False.
-
sort_inputs
(bool
, default:True
) –Whether to sort input synapses by presynaptic root id, ordered by synapse count. Defaults to True.
-
sort_outputs
(bool
, default:True
) –Whether to sort output synapses by presynaptic root id, ordered by postsynaptic synapse count. Defaults to True.
-
sort_ascending
(bool
, default:False
) –If sorting, whether to sort ascending (lowest synapse count to highest). Defaults to False.
-
input_color
(list(float) or str
, default:DEFAULT_POSTSYN_COLOR
) –Color of input synapse points as an RGB list [0, 1], hex string, or common name.
-
output_color
(list(float) or str
, default:DEFAULT_PRESYN_COLOR
) –Color of output synapse points as an RGB list [0, 1], hex string, or common name.
-
contrast
(list
, default:None
) –List of two floats between 0 and 1, specifying the black and white levels. If None, no contrast is set.
-
timestamp
(datetime
, default:None
) –Timestamp to use for the query. Defaults to None, which will use the materialized version.
-
view_kws
(dict
, default:None
) –Dictionary containing viewer settings for Neuroglancer. See nglui.StateBuilder for options. See the previous docstring for details on available keys.
-
point_column
(str
, default:'ctr_pt_position'
) –Column to pull synapse positions from. Defaults to "ctr_pt_position".
-
pre_pt_root_id_col
(str
, default:'pre_pt_root_id'
) –Column to pull presynaptic IDs for synapses from. Defaults to "pre_pt_root_id".
-
post_pt_root_id_col
(str
, default:'post_pt_root_id'
) –Column to pull postsynaptic IDs for synapses from. Defaults to "post_pt_root_id".
-
input_layer_name
(str
, default:'syns_in'
) –Name of the layer for input synapses. Defaults to "syns_in".
-
output_layer_name
(str
, default:'syns_out'
) –Name of the layer for output synapses. Defaults to "syns_out".
-
ngl_url
(str
, default:None
) –URL of the Neuroglancer instance to use. Defaults to the default viewer set in the datastack.
-
link_text
(str
, default:'Neuroglancer Link'
) –Text to use for the HTML return. Defaults to 'Neuroglancer Link'.
Raises:
-
ValueError
–If the specified point column is not present in the synapse table.
Returns:
-
IPython.HTML, str, or dict
–Representation of the Neuroglancer state, depending on the
return_as
parameter.
make_point_statebuilder(client, point_column='pt_position', linked_seg_column='pt_root_id', data_resolution=None, group_column=None, tag_column=None, description_column=None, contrast=None, view_kws=None, point_layer_name='pts', color=None, split_positions=False)
Generate a state builder that puts points on a single column with a linked segmentaton id
Parameters:
-
client
(CAVEclient
) –CAVEclient configured for the datastack desired
-
point_column
(str
, default:'pt_position'
) –Column in dataframe to pull points from. Defaults to "pt_position".
-
linked_seg_column
(str
, default:'pt_root_id'
) –column to link to segmentation, None for no column. Defaults to "pt_root_id".
-
group_column
(str, or list
, default:None
) –column(s) to group annotations by, None for no grouping (default=None)
-
tag_column
(str, optional)
, default:None
) –column to use for tags, None for no tags (default=None)
-
description_column
(str
, default:None
) –column to use for descriptions, None for no descriptions (default=None)
-
contrast
(list
, default:None
) –Two elements specifying the black level and white level as floats between 0 and 1, by default None. If None, no contrast is set.
-
view_kws
(dict
, default:None
) –dictionary of view keywords to configure neuroglancer view
-
split_positions
(bool
, default:False
) –whether the position column into x,y,z columns. Defaults to False.
Returns:
-
StateBuilder
–A statebuilder to make points with linked segmentations
make_pre_post_statebuilder(client, show_inputs=False, show_outputs=False, contrast=None, view_kws=None, point_column='ctr_pt_position', pre_pt_root_id_col='pre_pt_root_id', post_pt_root_id_col='post_pt_root_id', dataframe_resolution_pre=None, dataframe_resolution_post=None, input_layer_name='syns_in', output_layer_name='syns_out', input_layer_color=DEFAULT_POSTSYN_COLOR, output_layer_color=DEFAULT_PRESYN_COLOR, split_positions=False)
Function to generate ChainedStateBuilder with optional pre and post synaptic annotation layers
Parameters:
-
client
(CAVEclient
) –a CAVEclient configured for datastack to visualize
-
show_inputs
(bool
, default:False
) –whether to show input synapses. Defaults to False.
-
show_outputs
(bool
, default:False
) –whether to show output synapses.. Defaults to False.
-
contrast
(list
, default:None
) –Two elements specifying the black level and white level as floats between 0 and 1, by default None. If None, no contrast is set.
-
view_kws
(dict
, default:None
) –view_kws to configure statebuilder, see nglui.StateBuilder. Defaults to None. keys are: show_slices: Boolean sets if slices are shown in the 3d view. Defaults to False. layout: str
xy-3d
/xz-3d
/yz-3d
(sections plus 3d pane),xy
/yz
/xz
/3d
(only one pane), or4panel
(all panes). Default isxy-3d
. show_axis_lines: Boolean determines if the axis lines are shown in the middle of each view. show_scale_bar: Boolean toggles showing the scale bar. orthographic : Boolean toggles orthographic view in the 3d pane. position* : 3-element vector determines the centered location. zoom_image : float Zoom level for the imagery in units of nm per voxel. Defaults to 8. zoom_3d : float Zoom level for the 3d pane. Defaults to 2000. Smaller numbers are more zoomed in. -
point_column
(str
, default:'ctr_pt_position'
) –column to pull points for synapses from. Defaults to "ctr_pt_position".
-
pre_pt_root_id_col
(str
, default:'pre_pt_root_id'
) –column to pull pre synaptic ids for synapses from. Defaults to "pre_pt_root_id".
-
post_pt_root_id_col
(str
, default:'post_pt_root_id'
) –column to pull post synaptic ids for synapses from. Defaults to "post_pt_root_id".
-
input_layer_name
(str
, default:'syns_in'
) –name of layer for inputs. Defaults to "syns_in".
-
output_layer_name
(str
, default:'syns_out'
) –name of layer for outputs. Defaults to "syns_out".
-
split_positions
(bool
, default:False
) –whether the position column is split into x,y,z columns. Defaults to False.
Returns:
-
ChainedStateBuilder
–An instance of a ChainedStateBuilder configured to accept a list starting with None followed by optionally synapse input dataframe followed by optionally synapse output dataframe.
make_state_url(df, sb, client, ngl_url=None, target_site=None)
Generate a url from a neuroglancer state via a state server.
Parameters:
-
df
(DataFrame
) –Dataframe to pass through statebuilder
-
sb
(StateBuilder
) –Statebuilder to use to render data for link
-
client
(CAVEclient
) –CAVEclient configured with a state server
-
ngl_url
(str
, default:None
) –Neuroglancer deployment URL, by default None
-
target_site
(str
, default:None
) –Type of neuroglancer deployment to build link for, by default None. This value overrides automatic checking based on the provided url. Use
seunglab
for a Seung-lab branch and eithermainline
orcave-explorer
for the Cave Explorer or main Google branch.
Returns:
-
str
–Url to the uploaded neuroglancer state.
make_synapse_neuroglancer_link(synapse_df, client, return_as='html', shorten='always', contrast=None, point_column='ctr_pt_position', dataframe_resolution=None, group_connections=True, link_pre_and_post=True, ngl_url=None, view_kws=None, pre_post_columns=None, neuroglancer_link_text='Neuroglancer Link', color=None, split_positions=False, target_site=None)
Generate a neuroglancer link from a synapse dataframe as returned from CAVEclient.materialize.synapse_query.
Parameters:
-
synapse_df
(DataFrame
) –DataFrame where each row represents a synapse.
-
client
(CAVEclient
) –A CAVEclient instance.
-
return_as
(str
, default:'html'
) –How to return the URL. Valid options are: - 'html': Returns an IPython HTML element. - 'url': Returns a URL string. - 'json': Returns a dictionary representing the Neuroglancer state. Defaults to 'html'.
-
shorten
(str
, default:'always'
) –Whether to shorten the link. Valid options are: - 'always': Always shorten the link. - 'if_long': Shorten the link if it exceeds MAX_URL_LENGTH. - 'never': Never shorten the link. Defaults to 'always'.
-
contrast
(list
, default:None
) –List of two floats between 0 and 1, specifying the black and white levels. If None, no contrast is set.
-
point_column
(str
, default:'ctr_pt_position'
) –Column in the DataFrame containing synapse positions. Defaults to 'ctr_pt_position'.
-
dataframe_resolution
(list
, default:None
) –List of length 3, specifying the resolution units of the position column. If None, attempts to get the resolution from DataFrame metadata or client.info.viewer_resolution().
-
group_connections
(bool
, default:True
) –Whether to group synapses within the same connection (between the same neurons). Defaults to True.
-
link_pre_and_post
(bool
, default:True
) –Whether to link the synapse annotations to the pre- and post-synaptic partners. Defaults to True.
-
ngl_url
(str
, default:None
) –URL of the Neuroglancer instance to use. Defaults to client.info.viewer_site() or DEFAULT_NGL.
-
view_kws
(dict
, default:None
) –Dictionary containing viewer settings for Neuroglancer. Available keys: - show_slices: Boolean, sets if slices are shown in the 3D view. - layout: str, specifies the viewer layout (e.g., 'xy-3d', '4panel'). - show_axis_lines: Boolean, determines if axis lines are shown. - show_scale_bar: Boolean, toggles the scale bar. - orthographic: Boolean, toggles orthographic view in the 3D pane. - position: 3-element vector, sets the centered location. - zoom_image: float, zoom level for the imagery in nm per voxel. - zoom_3d: float, zoom level for the 3D pane.
-
pre_post_columns
(list
, default:None
) –List of two strings, specifying the column names for pre- and post-synaptic root_ids. Defaults to ['pre_pt_root_id', 'post_pt_root_id'].
-
neuroglancer_link_text
(str
, default:'Neuroglancer Link'
) –Text to use in the returned HTML link. Defaults to 'Neuroglancer Link'.
-
color
(list(float) or str
, default:None
) –Color of synapse points as an RGB list [0, 1], hex string, or common name.
-
split_positions
(bool
, default:False
) –Whether the position column is split into x, y, and z columns.
-
target_site
(str
, default:None
) –Type of neuroglancer deployment to build link for, by default None. This value overrides automatic checking based on the provided url. Use
seunglab
for a Seung-lab branch and eithermainline
orcave-explorer
for the Cave Explorer or main Google branch.
Returns:
-
IPython.HTML, str, or dict
–Representation of the Neuroglancer state, depending on the
return_as
parameter.
Raises:
-
ValueError
–If the specified
point_column
is not found in the DataFrame.
make_url_robust(df, sb, client, shorten='if_long', ngl_url=None, max_url_length=MAX_URL_LENGTH, target_site=None)
Generate a url from a neuroglancer state. If too long, return through state server, othewise return a url containing the data directly.
Parameters:
-
df
(DataFrame
) –Dataframe to pass through statebuilder
-
sb
(StateBuilder
) –Statebuilder to use to render data for link
-
client
(CAVEclient
) –CAVEclient configured with a state server
-
shorten
(str
, default:'if_long'
) –How to shorten link. one of 'if_long', 'always', 'never'. 'if_long' will use the state server to shorten links longer than nglui.statebuilder.MAX_URL_LENGTH (set to 1,750,000). 'always' will always use the state server to shorten the url 'never' will always return the full url. Defaults to "if_long".
-
ngl_url
(str
, default:None
) –Neuroglancer deployment URL, by default None
-
max_url_length
(int
, default:MAX_URL_LENGTH
) –Maximum length of url to return directly, by default 1_750_000
-
target_site
(str
, default:None
) –Type of neuroglancer deployment to build link for, by default None. This value overrides automatic checking based on the provided url. Use
seunglab
for a Seung-lab branch and eithermainline
orcave-explorer
for the Cave Explorer or main Google branch.
Returns:
-
str
–URL containing the state created by the statebuilder.
package_state(df, sb, client, shorten='if_long', return_as='url', ngl_url=None, link_text='Neuroglancer Link', target_site=None)
Automate creating a state from a statebuilder and a dataframe, return it in the desired format, shortening if desired.
Parameters:
-
df
(DataFrame
) –Dataframe to pass through statebuilder
-
sb
(StateBuilder
) –Statebuilder to use to render data for link
-
client
(CAVEclient
) –CAVEclient configured with a state server
-
shorten
(str
, default:'if_long'
) –How to shorten link. one of 'if_long', 'always', 'never'. 'if_long' will use the state server to shorten links longer than nglui.statebuilder.MAX_URL_LENGTH (set to 1,750,000). 'always' will always use the state server to shorten the url 'never' will always return the full url. Defaults to "if_long".
-
return_as
(str
, default:'url'
) –How to return the state. one of 'html', 'url', 'json'. 'html' will return an ipython clickable link 'url' will return a string with the url 'json' will return the state as a dictionary
-
ngl_url
(str
, default:None
) –Neuroglancer deployment URL, by default None
-
link_text
(str
, default:'Neuroglancer Link'
) –Text to use for the link, by default "Neuroglancer Link"
-
target_site
(str
, default:None
) –Type of neuroglancer deployment to build link for, by default None. This value overrides automatic checking based on the provided url. Use
seunglab
for a Seung-lab branch and eithermainline
orcave-explorer
for the Cave Explorer or main Google branch.
Returns:
segment_property_link(seg_props, client, ngl_url=None, return_as='html')
Returns a basic link to a default neuroglancer state and segment properties.
Parameters:
-
seg_props
(SegmentProperties or str
) –A segment propeties object or a URL to a segment properties.
-
client
(CAVEclient
) –A caveclient object.
-
ngl_url
(str
, default:None
) –URL for a neuroglancer deployment, by default None which uses a default Spelunker deployment.
-
return_as
(str
, default:'html'
) –Select how the data comes back from statebuilder, by default "html". See statebuilder.render_state for more information.
Returns:
-
string or Viewer
–
sort_dataframe_by_root_id(df, root_id_column, ascending=False, num_column='n_times', drop=False)
Sort a dataframe so that rows belonging to the same root id are together, ordered by how many times the root id appears.
Parameters:
-
df
(DataFrame
) –dataframe to sort
-
root_id_column
(str
) –Column name to use for sorting root ids
-
ascending
(bool
, default:False
) –Whether to sort ascending (lowest count to highest) or not, by default False
-
num_column
(str
, default:'n_times'
) –Temporary column name to use for count information, by default 'n_times'
-
drop
(bool
, default:False
) –If True, drop the additional column when returning.
Returns: