Annotation¶
Module to handle label and annotation info from Allen Brain Atlas (v2).
Notes
The files containting annotation information is assumed to be in the path stored in
atlas_path
, which defaults to the resource pathClearMap.Settings.resources_path
.The annotation file is assumed to be ‘annotation_25_full.nrrd’ but can be set via
default_annotation_file
.The mapping between labels and brain area information is assumed to be in the ‘annotation.json’ file but the location can be set via
default_label_file
.
References
-
class
Annotation
(label_file=None, extra_label=None, annotation_file=None)[source]¶ Bases:
object
Class that holds information of the annotated regions.
-
convert_label
(label, key='order', value='graph_order', node=None, level=None, method='map')[source]¶
-
property
max_level
¶
-
property
n_structures
¶
-
-
class
Label
(data, children=None, parent=None, level=0)[source]¶ Bases:
object
Class holding information of an individual Atlas label.
-
property
id
¶
-
property
level
¶
-
property
name
¶
-
property
order
¶
-
property
-
color_map
(alpha=True, as_int=False, int_type='uint8')[source]¶ Generates a color map from color ids to rgb
Arguments
- alphabool
If True return a color map with alpha values.
Returns
- color_maparray
An array of rgb colors for each label.
-
convert_label
(label, key='id', value='order', level=None, method=None)[source]¶ Convert label using the atlas annotation data.
Arguments
- lablearray
List of labels to convert.
- keystr
The key corresponding to the label.
- valuestr
The key to ocnvert the lable to.
- levelnt or None
Convert at this level of the hierarchy. I fNone use full hierarchy.
- method‘map’ or ‘dictionary’
Convert labels using a mapping array or a dictionary. Depending on the keys either can be faster for large data sets.
Returns
- labelarray
List of converted labels.
-
convert_label_to_color
(label, key='id', level=None, alpha=True, as_int=False, int_type='uint8')[source]¶ Convert label using the atlas annotation colors.
Arguments
- lablearray
List of labels to convert.
- keystr
The key corresponding to the label.
- levelnt or None
Convert at this level of the hierarchy. I fNone use full hierarchy.
- alphabool
If True, return rgba values.
- as_intbool
If True, return rgb valueas as int between 0 and 255.
- int_typedtype
Type for the color array.
Returns
- colorsarray
List of colors for each label.
-
count_label
(label, weights=None, key='order', hierarchical=True)[source]¶ Counts the label within the various structures, taking into account the sub-structures.
Arguments
- labelarray
List of labels.
- weightsarray
Optional list of weights for each label.
- keystr
The key the lables are given in.
- hierarchicalbool
If True, count all sub-labels.
Returns
- binsarray
The counts for each label.
-
count_points
(points, weights=None, annotation_file=None, invalid=0, hierarchical=True)[source]¶ Counts the points within the various structures, taking into account the sub-structures.
Arguments
- pointsarray
Array of nxdim points to annotate and count.
- weightsarray or None
Optional intensity values to weight the count.
- annotation_filestr
File name of the atlas annotation.
- invalidint
Label for invalid points.
- hierarchicalbool
If True, count all sub-labels.
Returns
- binsarray
The counts for each label.
-
find
(label, key='id', value=None, node=None, level=None)¶
-
format_annotation_filename
(filename, orientation=None, slicing=None, postfix=None, directory=None)[source]¶ Formats the annotation filename given oriantion and slicing.
-
get_dictionary
(key, value, node=None, level=None, ordered=False)¶
-
get_list
(key=None, node=None, level=None)¶
-
get_map
(key, value, node=None, level=None)¶
-
label_points
(points, annotation_file=None, invalid=0, key='order', level=None)[source]¶ Label points according to the annotation in the labeled image file.
Arguments
- pointsarray
Array of nxdim point coordinates to be labeled.
- annotation_filestr
File name of the atals annotation.
- invalidint
Label for invalid points.
- keystr
The key of the label, by default the order of the labels.
Returns
- labelarray
Label of the points corresponding to the given key.
-
prepare_annotation_files
(slicing=None, orientation=None, directory=None, postfix=None, annotation_file=None, reference_file=None, distance_to_surface_file=None, overwrite=False, verbose=False)[source]¶ Crop the annotation, reference and distance files to match the data.
Arguments
- slicingtuple or None
The slice specification after reorienting.
- orientationtuple, str or None.
The orientation specification. Strings can be ‘left’ or ‘right’, for the two hemispheres.
- directorystr or None
The target directory. If None, use ClearMap resources folder.
- postfixstr or None
Use this postfix for the cropped annotation file. If None and automatic label is choosen.
- annotation_filestr or None
The annotation file to use.
- reference_filestr or None
The reference file to use.
- distance_to_surface_filestr or None
The distance file to use.
- overwritebool
If True, overwrite exisitng files.
Returns
- annotation_filestr
The cropped annotation file.
- reference_filestr
The cropped reference file.
- distance_to_surface_filestr
The distance cropped file.
-
write_color_annotation
(filename, annotation_file=None)[source]¶ Creates a rgb image from the atlas color data.
Arguments
- filenamestr
The name of the color palette file.
- annotation_filestr
File name of the atals annotation.
Returns
- filenamestr
The name of the file to which the color atlas was written.
-
write_color_palette
(filename=None)[source]¶ Creates a pal or lut file for imaris or imagej based on label colors of atlas.
Arguments
- filenamestr
The name of the color palette file.
Returns
- filenamestr
The name of the file to which the color palette was written.
-
annotation
= Annotation(1319)[11]{/home/ckirst/Programs/ClearMap2/ClearMap/Resources/Atlas/ABA_annotation.json}¶ Information on the annotated regions
-
atlas_path
= '/home/ckirst/Programs/ClearMap2/ClearMap/Resources/Atlas'¶ Default path to atlas infomration.
-
default_annotation_file
= '/home/ckirst/Programs/ClearMap2/ClearMap/Resources/Atlas/ABA_25um_annotation.tif'¶ Default volumetric annotated image file.
Note
This file is by default the Allen brain annotated mouse atlas with 25um isotropic resolution.
-
default_distance_to_surface_file
= '/home/ckirst/Programs/ClearMap2/ClearMap/Resources/Atlas/ABA_25um_distance_to_surface.tif'¶ Default volumetric annotated image file.
Note
This file is by default the Allen brain annotated mouse atlas with 25um isotropic resolution.
-
default_extra_label
= [(182305696, 453, 'No label', 'NoL'), (182305712, 453, 'No label', 'NoL'), (312782560, 315, 'No label', 'NoL'), (312782592, 453, 'No label', 'NoL'), (312782656, 315, 'No label', 'NoL'), (526157184, 993, 'No label', 'NoL'), (526322272, 500, 'No label', 'NoL'), (527696992, 315, 'No label', 'NoL')]¶ Additional label not in the Allen Brain Atlas label but in the atlas image.
Note
The form is a list of tuples, each tuple has the form (atlas id, parent id, name, acronym).
-
default_label_file
= '/home/ckirst/Programs/ClearMap2/ClearMap/Resources/Atlas/ABA_annotation.json'¶ Default list of labels and region names in the annotated image.
Note
This file is by default the labels for the Allen brain annotated mouse atlas with 25um isotropic resolution.
-
default_reference_file
= '/home/ckirst/Programs/ClearMap2/ClearMap/Resources/Atlas/ABA_25um_reference.tif'¶ Default volumetric annotated image file.
Note
This file is by default the Allen brain annotated mouse atlas with 25um isotropic resolution.