Esempio n. 1
0
    def get_compartments(self, penetration_id: str):
        """Get compartments for each point in `penetration_id`."""
        if not self.has_penetration(penetration_id):
            return

        ccf_coord = self.get_coordinates(
            penetration_id)  # loads this penetration
        annotation_volume = self.cache.load_annotation_volume()
        tree = StructureTree(self.cache.load_structure_graph())

        i, j, k = (ccf_coord.T / self.settings.system.resolution).astype(
            np.int)
        cids = annotation_volume[i, j, k]

        structures = tree.get_structures_by_id(cids)
        return [self._jsonify_compartment(s) for s in structures]
Esempio n. 2
0
    def get_compartment_tree(self):
        """Get the entire compartment hierarchy."""
        def populate_children(tr: StructureTree, node: dict):
            # make corrections to field names
            node = self._jsonify_compartment(node)
            node["children"] = []

            for child in tr.children([node["id"]])[0]:
                node["children"].append(populate_children(tr, child))

            return node

        tree = StructureTree(self.cache.load_structure_graph())
        root = tree.get_structures_by_id([997])[0]
        root["rgb_triplet"] = 3 * [135]
        root = populate_children(tree, root)

        return root
# this is a string which contains the name of the latest ccf version
annotation_version = MouseConnectivityApi.CCF_VERSION_DEFAULT

mcapi = MouseConnectivityApi()
#Next line commented because the annotation volume is already downloaded
mcapi.download_annotation_volume(annotation_version, 10, annotation_path)

annotation, meta = nrrd.read(annotation_path)

swapped_ann = np.swapaxes(annotation, 1, 2)
swapped_ann = swapped_ann[:, :, ::
                          -1]  #Revert the z axis so the 0 is the ventral part

rsp = ReferenceSpace(tree, swapped_ann, [10, 10, 10])

root_path = "E:\\Histology\\brain_structures_half_not_close_10\\"
##Here comes the obj creation
for struct in structure_graph[:1]:
    path_parent = ""
    for parent_id in struct["structure_id_path"][:-1]:
        name_parent = tree.get_structures_by_id([parent_id])[0]["acronym"]
        name_parent = name_parent.replace("/", "-")
        path_parent = path_parent + name_parent + "\\"
    struct_id = struct["id"]
    name = tree.get_structures_by_id(
        [struct_id])[0]["name"] + " (" + tree.get_structures_by_id(
            [struct_id])[0]["acronym"] + ")"
    name = name.replace("/", "-")
    export_obj(struct_id, name, root_path + path_parent)
    print(struct["name"])