Skip to content

Instantly share code, notes, and snippets.

@NileGraddis
Created October 28, 2019 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NileGraddis/6a55fc73bb63700b1adf120c479a01f3 to your computer and use it in GitHub Desktop.
Save NileGraddis/6a55fc73bb63700b1adf120c479a01f3 to your computer and use it in GitHub Desktop.
import os
import numpy as np
from allensdk.core.reference_space_cache import ReferenceSpaceCache
resolution = 100 # in microns, options are (10, 25, 50, 100).
cache = ReferenceSpaceCache(
manifest=os.path.join("allen_ccf", "manifest.json"), # downloaded files are stored relative to here
resolution=resolution,
reference_space_key="annotation/ccf_2017" # use the latest version of the CCF
)
# The annotation volume maps voxels to structures
annotation, _ = cache.get_annotation_volume()
# the structure tree hold detailed information about annotated structures
structure_tree = cache.get_structure_tree()
# Some coordinate, in microns
coordinate = np.array([
5231.15, # anterior -> posterior
1500.0, # dorsal -> ventral
5200.79 # left -> right
])
voxel = np.round(coordinate / resolution).astype(int)
structure_id = annotation[voxel[0], voxel[1], voxel[2]]
# Each voxel in the annotation volume is annotated as specifically as possible
structure = structure_tree.get_structures_by_id([structure_id])[0]
print(structure)
print("============")
# Structures are organized hierarchically by containment.
ancestors = structure_tree.get_structures_by_id(structure["structure_id_path"])
for ancestor in ancestors[::-1]:
print(ancestor["name"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment