annotationframeworkclient package¶
Submodules¶
annotationframeworkclient.annotationengine module¶
-
class
annotationframeworkclient.annotationengine.
AnnotationClient
(server_address=None, dataset_name=None, cg_server_address=None)¶ Bases:
object
-
bulk_import_df
(table_name, data_df, min_block_size=40, dataset_name=None, n_threads=16, n_retries=100)¶ Imports all annotations from a single dataframe in one go
Parameters: - dataset_name – str
- table_name – str
- data_df – pandas DataFrame
Returns:
-
cg_server_address
¶
-
create_table
(table_name, schema_name, dataset_name=None)¶ Creates a table
Parameters: - table_name – str
- schema_name – str
- dataset_name – str
Returns: response
-
dataset_name
¶
-
default_url_mapping
¶
-
delete_annotation
(table_name, annotation_id, dataset_name=None)¶ Delete an existing annotation
Parameters: - dataset_name – str
- table_name – str
- annotation_id – int
:return dict
-
get_annotation
(table_name, annotation_id, dataset_name=None)¶ Returns information about one specific annotation
Parameters: - dataset_name – str
- table_name – str
- annotation_id – np.uint64
:return dict
-
get_dataset_info
(dataset_name=None)¶ Returns information about a dataset
Calls get_dataset_info from informationserviceclient
Parameters: dataset_name – str Returns: dict
-
get_datasets
()¶ Returns existing datasets
Returns: list
-
get_root_id
(supervoxel_id, dataset_name=None)¶
-
get_root_id_under_point
(xyz, dataset_name=None)¶
-
get_supervoxel
(xyz, dataset_name=None)¶
-
get_tables
(dataset_name=None)¶ Reads table infos
Parameters: dataset_name – str Returns: dict
-
infoserviceclient
()¶
-
post_annotation
(table_name, data, dataset_name=None)¶ Post an annotation to the AnnotationEngine
Parameters: - dataset_name – str
- table_name – str
- data – dict
:return dict
-
server_address
¶
-
update_annotation
(table_name, annotation_id, data, dataset_name=None)¶ Updates an existing annotation
Parameters: - table_name – str
- annotation_id – np.uint64
- data – dict
- dataset_name – str
Returns: dict
-
annotationframeworkclient.chunkedgraph module¶
-
class
annotationframeworkclient.chunkedgraph.
ChunkedGraphClient
(server_address=None, dataset_name=None, table_name=None)¶ Bases:
object
-
cloudvolume_path
¶
-
default_url_mapping
¶
-
get_change_log
(root_id)¶
-
get_children
(node_id)¶ get the children of any node in the hierarchy
Parameters: node_id – np.uint64 Returns: list of np.uint64
-
get_contact_sites
(root_id, bounds=None, calc_partners=False)¶
-
get_leaves
(root_id, bounds=None)¶ get the supervoxels for this root_id
root_id: uint64 root id to find supervoxels for bounds: 3x2 numpy array of bounds [[minx,maxx],[miny,maxy],[minz,maxz]]
-
get_merge_log
(root_id)¶
-
get_root_id
(supervoxel_id, timestamp=None)¶
-
-
annotationframeworkclient.chunkedgraph.
package_bounds
(bounds)¶
annotationframeworkclient.emannotationschemas module¶
annotationframeworkclient.endpoints module¶
annotationframeworkclient.imagery module¶
-
class
annotationframeworkclient.imagery.
ImageryClient
(image_source=None, segmentation_source=None, server_address=None, dataset_name=None, base_resolution=[4, 4, 40], graphene_segmentation=True, table_name=None, image_mip=0, segmentation_mip=0, segmentation=True, imagery=True)¶ Bases:
object
Class to help download imagery and segmentation data. Can either take explicit cloudvolume paths for imagery and segmentation or use the Info Service to look up the right paths.
- image_source : str, optional
- CloudVolume path to an imagery source, by default None
- segmentation_source : str, optional
- CloudVolume path to a segmentation source, by default None
- server_address : str, optional
- Address of an InfoService host, by default None. If none, defaults to https://www.dynamicannotationframework.com
- dataset_name : str, optional
- Dataset name to lookup information for in the InfoService, by default None
- base_resolution : list, optional
- Sets the voxel resolution that bounds will be entered in, by default [4, 4, 40].
- graphene_segmentation : bool, optional
- If true, use the graphene segmentation. If false, use the flat segmentation. By default True.
- table_name : str, optional
- Name of the chunkedgraph table (if used), by default None
- image_mip : int, optional
- Default mip level to use for imagery lookups, by default 0. Note that the same mip level for imagery and segmentation can correspond to different voxel resolutions.
- segmentation_mip : int, optional
- Default mip level to use for segmentation lookups, by default 0.
- segmentation : bool, optional
- If False, no segmentation cloudvolume is initialized. By default True
- imagery : bool, optional
- If False, no imagery cloudvolume is initialized. By default True
-
base_resolution
¶ The voxel resolution assumed when locations are used for the client.
Returns: X, y, and z voxel resolution. Return type: list
-
image_and_segmentation_cutout
(bounds, image_mip=None, segmentation_mip=None, root_ids='all', resize=True, split_segmentations=False, include_null_root=False, verbose=False)¶ Download aligned and scaled imagery and segmentation data at a given resolution.
Parameters: - bounds (2x3 list of ints) – A list of the lower and upper bound point for the cutout. The units are voxels in the resolution set by the base_resolution parameter.
- image_mip (int, optional) – Mip level of the imagery if something other than the default is wanted, by default None
- segmentation_mip (int, optional) – Mip level of the segmentation if something other than the default is wanted, by default None
- root_ids (list, None, or 'all', optional) – If a list, the segmentation cutout only includes voxels for a specified set of root ids. If None, default to the supervoxel ids. If ‘all’, finds all root ids corresponding to the supervoxels in the cutout and get all of them. By default ‘all’.
- resize (bool, optional) – If True, upscale the lower resolution cutout to the same resolution of the higher one (either imagery or segmentation).
- split_segmentations (bool, optional) – If True, the segmentation is returned as a dict of masks (using split_segmentation_cutout), and if False returned as an array with root_ids (using segmentation_cutout), by default False
- include_null_root (bool, optional) – If True, includes root id of 0, which is usually reserved for a null segmentation value. Default is False.
- verbose (bool, optional) – If True, prints statements about the progress as it goes. By default, False.
Returns: - cloudvolume.VolumeCutout – Imagery volume cutout
- numpy.ndarray or dict – Segmentation volume cutout as either an ndarray or dict of masks depending on the split_segmentations flag.
-
image_cutout
(bounds, mip=None)¶ Get an image cutout for a certain location or set of bounds and a mip level.
Parameters: - bounds (2 x 3 list of ints) – A list of a lower bound and upper bound point to bound the cutout in units of voxels in a resolution set by the base_resolution parameter
- mip (int, optional) – Mip level of imagery to get if something other than the default is wanted, by default None
Returns: An n-d image of the image requested with image intensity values as the elements.
Return type: cloudvolume.VolumeCutout
-
image_cv
¶ Imagery CloudVolume
-
image_resolution_to_mip
(resolution)¶ Gets the image mip level for a specified voxel resolution, if it exists
Parameters: resolution (3 element array-like) – x, y, and z resolution per voxel. Returns: If the resolution has a mip level for the imagery volume, returns it. Otherwise, returns None. Return type: int or None
-
image_source
¶ Image Cloudvolume path
-
info
¶ InfoClient for the imagery dataset (if set)
-
mip_resolutions
()¶ Gets a dict of resolutions and mip levels available for the imagery and segmentation volumes
Returns: - dict – Keys are voxel resolution tuples, values are mip levels in the imagery volume as integers
- dict – Keys are voxel resolution tuples, values are mip levels in the segmentation volume as integers
-
pcg_client
¶ PychunkedGraph client object
-
save_image_and_segmentation_masks
(filename_prefix, bounds=None, image_mip=None, segmentation_mip=None, root_ids='all', resize=True, precomputed_data=None, slice_axis=2, segmentation_colormap={}, include_null_root=False, verbose=False, **kwargs)¶ Save aligned and scaled imagery and segmentation mask cutouts as pngs. Kwargs are passed to imageio.imwrite.
Parameters: - filename_prefix (str) – Prefix for the segmentation filenames. The full filename will be either {filename_prefix}_root_id_{root_id}.png or {filename_prefix}_root_id_{root_id}_{i}.png, depending on if multiple slices of each root id are saved.
- bounds (2x3 list of ints, optional) – A list of the lower and upper bound point for the cutout. The units are voxels in the resolution set by the base_resolution parameter. Only used if a precomputed data is not passed. By default, None.
- image_mip (int, optional) – Only used if a precomputed data is not passed. Mip level of imagery to get if something other than the default is wanted, by default None.
- segmentation_mip (int, optional) – Only used if precomputed data is not passed. Mip level of segmentation to get if something other than the default is wanted, by default None
- root_ids (list, None, or 'all', optional) – If a list, the segmentation cutout only includes voxels for a specified set of root ids. If None, default to the supervoxel ids. If ‘all’, finds all root ids corresponding to the supervoxels in the cutout and get all of them. By default ‘all’.
- resize (bool, optional) – If True, upscale the lower resolution cutout to the same resolution of the higher one (either imagery or segmentation).
- precomputed_data (tuple, optional) – Already computed tuple with imagery and segmentation mask data, in that order. If not provided, bounds must be given to download cutout data. By default, None.
- slice_axis (int, optional) – If the image data is truly 3 dimensional, determines which axis to use to save serial images, by default 2 (i.e. z-axis)
- segmentation_colormap (dict, optional) – A dict of root ids to an uint8 RGB color triplet (0-255) or RGBa quadrooplet to optionally color the mask png. Any root id not specified will be rendered in white. Color triplets default to full opacity. Default is an empty dictionary.
- include_null_root (bool, optional) – If True, includes root id of 0, which is usually reserved for a null segmentation value. By default, False.
- verbose (bool, optional) – If True, prints the progress, by default False
-
save_imagery
(filename_prefix, bounds=None, mip=None, precomputed_image=None, slice_axis=2, verbose=False, **kwargs)¶ Save queried or precomputed imagery to png files.
Parameters: - filename_prefix (str) – Prefix for the imagery filename. The full filename will be {filename_prefix}_imagery.png
- bounds (2x3 list of ints, optional) – A list of the lower and upper bound point for the cutout. The units are voxels in the resolution set by the base_resolution parameter. Only used if a precomputed image is not passed. By default, None.
- mip (int, optional) – Only used if a precomputed image is not passed. Mip level of imagery to get if something other than the default is wanted, by default None
- precomputed_image (cloudvolume.VolumeCutout, optional) – Already downloaded VolumeCutout data to save explicitly. If called this way, the bounds and mip arguments will not apply. If a precomputed image is not provided, bounds must be specified to download the cutout data. By default None
- slice_axis (int, optional) – If the image data is truly 3 dimensional, determines which axis to use to save serial images, by default 2 (i.e. z-axis)
- verbose (bool, optional) – If True, prints the progress, by default False
-
save_segmentation_masks
(filename_prefix, bounds=None, mip=None, root_ids='all', precomputed_masks=None, slice_axis=2, include_null_root=False, segmentation_colormap={}, verbose=False, **kwargs)¶ Save queried or precomputed segmentation masks to png files. Additional kwargs are passed to imageio.imwrite.
Parameters: - filename_prefix (str) – Prefix for the segmentation filenames. The full filename will be either {filename_prefix}_root_id_{root_id}.png or {filename_prefix}_root_id_{root_id}_{i}.png, depending on if multiple slices of each root id are saved.
- bounds (2x3 list of ints, optional) – A list of the lower and upper bound point for the cutout. The units are voxels in the resolution set by the base_resolution parameter. Only used if a precomputed segmentation is not passed. By default, None.
- mip (int, optional) – Only used if a precomputed segmentation is not passed. Mip level of segmentation to get if something other than the default is wanted, by default None
- root_ids (list, None, or 'all', optional) – If a list, the segmentation cutout only includes voxels for a specified set of root ids. If None, default to the supervoxel ids. If ‘all’, finds all root ids corresponding to the supervoxels in the cutout and get all of them. By default ‘all’.
- precomputed_masks (dict, optional) – Already downloaded dict of mask data to save explicitly. If called this way, the bounds and mip arguments will not apply. If precomputed_masks are not provided, bounds must be given to download cutout data. By default None
- slice_axis (int, optional) – If the image data is truly 3 dimensional, determines which axis to use to save serial images, by default 2 (i.e. z-axis)
- include_null_root (bool, optional) – If True, includes root id of 0, which is usually reserved for a null segmentation value. Default is False.
- segmentation_colormap (dict, optional) – A dict of root ids to an uint8 RGB color triplet (0-255) or RGBa quadrooplet to optionally color the mask png. Any root id not specified will be rendered in white. Color triplets default to full opacity. Default is an empty dictionary.
- verbose (bool, optional) – If True, prints the progress, by default False
-
segmentation_cutout
(bounds, root_ids='all', mip=None, verbose=False)¶ Get a cutout of the segmentation imagery for some or all root ids between set bounds. Note that if all root ids are requested in a large region, it could take a long time to query all supervoxels.
Parameters: - bounds (2x3 list of ints) – A list of the lower and upper bound point for the cutout. The units are voxels in the resolution set by the base_resolution parameter.
- root_ids (list, None, or 'all', optional) – If a list, only compute the voxels for a specified set of root ids. If None, default to the supervoxel ids. If ‘all’, find all root ids corresponding to the supervoxels in the cutout and get all of them. None, by default ‘all’
- mip (int, optional) – Mip level of the segmentation if something other than the defualt is wanted, by default None
- verbose (bool, optional) – If true, prints statements about the progress as it goes. By default, False.
Returns: Array whose elements correspond to the root id (or, if root_ids=None, the supervoxel id) at each voxel.
Return type: numpy.ndarray
-
segmentation_cv
¶ Segmentation CloudVolume object
-
segmentation_masks
(seg_img, include_null_root=False)¶ Convert a segmentation array into a dict of binary masks for each root id.
Parameters: - seg_img (numpy.ndarray) – Array with voxel values corresponding to the object id at that voxel
- include_null_root (bool, optional) – Create a mask for 0 id, which usually denotes no object, by default False
Returns: Dict of binary masks. Keys are root ids, values are boolean n-d arrays with a 1 where that object is.
Return type: dict
-
segmentation_resolution_to_mip
(resolution)¶ Gets the segmentation mip level for a specified voxel resolution, if it exists
Parameters: resolution (3 element array-like) – x, y, and z resolution per voxel. Returns: If the resolution has a mip level for the segmentation volume, returns it. Otherwise, returns None. Return type: int or None
-
segmentation_source
¶ Segmentation CloudVolume path
-
split_segmentation_cutout
(bounds, root_ids='all', mip=None, include_null_root=False, verbose=False)¶ Generate segmentation cutouts with a single binary mask for each root id, organized as a dict with keys as root ids and masks as values.
Parameters: - bounds (2x3 list of ints) – A list of the lower and upper bound point for the cutout. The units are voxels in the resolution set by the base_resolution parameter.
- root_ids (list, None, or 'all', optional) – If a list, only compute the voxels for a specified set of root ids. If None, default to the supervoxel ids. If ‘all’, find all root ids corresponding to the supervoxels in the cutout and get all of them. None, by default ‘all’
- mip (int, optional) – Mip level of the segmentation if something other than the default is wanted, by default None
- include_null_root (bool, optional) – If True, includes root id of 0, which is usually reserved for a null segmentation value. Default is False.
- verbose (bool, optional) – If true, prints statements about the progress as it goes. By default, False.
Returns: Dict whose keys are root ids and whose values are the binary mask for that root id, with a 1 where the object contains the voxel.
Return type: dict
-
annotationframeworkclient.imagery.
colorize_masks
(mask_dict, colormap, default_color=[255, 255, 255, 255])¶ Colorize a dict of masks using a dict of RGB (or RGBa) colors.
Parameters: - mask_dict (dict) – Dict mapping root ids to binary masks.
- colormap (dict) – Dict mapping root ids to a 3 or 4 element RGBa color between 0-255.
- default_color (list, optional) – RGBa color value between 0-255, by default [255, 255, 255, 255]
Returns: Dict mapping root ids to RGBa color images.
Return type: dict
-
annotationframeworkclient.imagery.
grayscale_to_rgba
(img)¶ Convert a
Parameters: img (numpy.ndarray) – NxM array of values beteen 0-255. Returns: NxMx4 numpy array with the same grayscale colors. Return type: numpy.ndarray
annotationframeworkclient.infoservice module¶
-
class
annotationframeworkclient.infoservice.
InfoServiceClient
(server_address=None, dataset_name=None)¶ Bases:
object
-
annotation_endpoint
(dataset_name=None, use_stored=True)¶
-
dataset_name
¶
-
default_url_mapping
¶
-
flat_segmentation_source
(dataset_name=None, use_stored=True, format_for='raw')¶
-
get_dataset_info
(dataset_name=None, use_stored=True)¶
-
get_datasets
()¶ Query which datasets are available at the info service
Returns: List of dataset names Return type: list
-
graphene_source
(dataset_name=None, use_stored=True, format_for='raw')¶
-
image_source
(dataset_name=None, use_stored=True, format_for='raw')¶
-
pychunkedgraph_endpoint
(dataset_name=None, use_stored=True)¶
-
pychunkedgraph_segmentation_source
(dataset_name=None, use_stored=True, format_for='raw')¶
-
pychunkedgraph_viewer_source
(**kwargs)¶
-
pychunkgraph_endpoint
(**kwargs)¶
-
pychunkgraph_segmentation_source
(**kwargs)¶
-
refresh_stored_data
()¶
-
server_address
¶
-
supervoxel_source
(dataset_name=None, use_stored=True, format_for='raw')¶
-
synapse_segmentation_source
(dataset_name=None, use_stored=True, format_for='raw')¶
-
-
annotationframeworkclient.infoservice.
format_cloudvolume
(objurl)¶
-
annotationframeworkclient.infoservice.
format_graphene
(objurl)¶
-
annotationframeworkclient.infoservice.
format_precomputed_https
(objurl)¶
-
annotationframeworkclient.infoservice.
format_precomputed_neuroglancer
(objurl)¶
-
annotationframeworkclient.infoservice.
format_raw
(objurl)¶