allensdk.core.reference_space_cache module

class allensdk.core.reference_space_cache.ReferenceSpaceCache(resolution, reference_space_key, **kwargs)[source]

Bases: Cache

ANNOTATION_KEY = 'ANNOTATION'
MANIFEST_VERSION = 1.2
REFERENCE_SPACE_VERSION_KEY = 'REFERENCE_SPACE_VERSION'
STRUCTURES_KEY = 'STRUCTURES'
STRUCTURE_MASK_KEY = 'STRUCTURE_MASK'
STRUCTURE_MESH_KEY = 'STRUCTURE_MESH'
STRUCTURE_TREE_KEY = 'STRUCTURE_TREE'
TEMPLATE_KEY = 'TEMPLATE'
add_manifest_paths(manifest_builder)[source]

Construct a manifest for this Cache class and save it in a file.

Parameters:
file_name: string

File location to save the manifest.

get_annotation_volume(file_name=None)[source]

Read the annotation volume. Download it first if it doesn’t exist.

Parameters:
file_name: string

File name to store the annotation volume. If it already exists, it will be read from this file. If file_name is None, the file_name will be pulled out of the manifest. Default is None.

get_reference_space(structure_file_name=None, annotation_file_name=None)[source]

Build a ReferenceSpace from this cache’s annotation volume and structure tree. The ReferenceSpace does operations that relate brain structures to spatial domains.

Parameters:
structure_file_name: string

File name to save/read the structures table. If file_name is None, the file_name will be pulled out of the manifest. If caching is disabled, no file will be saved. Default is None.

annotation_file_name: string

File name to store the annotation volume. If it already exists, it will be read from this file. If file_name is None, the file_name will be pulled out of the manifest. Default is None.

get_structure_mask(structure_id, file_name=None, annotation_file_name=None)[source]

Read a 3D numpy array shaped like the annotation volume that has non-zero values where voxels belong to a particular structure. This will take care of identifying substructures.

Parameters:
structure_id: int

ID of a structure.

file_name: string

File name to store the structure mask. If it already exists, it will be read from this file. If file_name is None, the file_name will be pulled out of the manifest. Default is None.

annotation_file_name: string

File name to store the annotation volume. If it already exists, it will be read from this file. If file_name is None, the file_name will be pulled out of the manifest. Default is None.

Notes

This method downloads structure masks from the Allen Institute. To make your own locally, see ReferenceSpace.many_structure_masks.

get_structure_mesh(structure_id, file_name=None)[source]

Obtain a 3D mesh specifying the surface of an annotated structure.

Parameters:
structure_id: int

ID of a structure.

file_name: string

File name to store the structure mesh. If it already exists, it will be read from this file. If file_name is None, the file_name will be pulled out of the manifest. Default is None.

Returns:
verticesnp.ndarray

Dimensions are (nSamples, nCoordinates=3). Locations in the reference space of vertices

vertex_normalsnp.ndarray

Dimensions are (nSample, nElements=3). Vectors normal to vertices.

face_verticesnp.ndarray

Dimensions are (sample, nVertices=3). References are given in indices (0-indexed here, but 1-indexed in the file) of vertices that make up each face.

face_normalsnp.ndarray

Dimensions are (sample, nNormals=3). References are given in indices (0-indexed here, but 1-indexed in the file) of vertex normals that make up each face.

Notes

These meshes are meant for 3D visualization and as such have been smoothed. If you are interested in performing quantative analyses, we recommend that you use the structure masks instead.

get_structure_tree(file_name=None, structure_graph_id=1)[source]

Read the list of adult mouse structures and return an StructureTree instance.

Parameters:
file_name: string

File name to save/read the structures table. If file_name is None, the file_name will be pulled out of the manifest. If caching is disabled, no file will be saved. Default is None.

structure_graph_id: int

Build a tree using structure only from the identified structure graph.

get_template_volume(file_name=None)[source]

Read the template volume. Download it first if it doesn’t exist.

Parameters:
file_name: string

File name to store the template volume. If it already exists, it will be read from this file. If file_name is None, the file_name will be pulled out of the manifest. Default is None.

classmethod validate_structure_id(structure_id)[source]
classmethod validate_structure_ids(structure_ids)[source]