Mentions légales du service

Skip to content
Snippets Groups Projects
glial_cmp.py 1.55 KiB
Newer Older
DEBREUVE Eric's avatar
DEBREUVE Eric committed
from __future__ import annotations

from type import array_t, site_path_h

import numpy as np_


class glial_cmp_t:
    #
    __slots__ = ("uid", "sites", "connection_path", "extensions", "img_shape")

    def __init__(self):
        #
        self.uid = None
        self.sites = None
        self.connection_path = None
        self.extensions = None
        self.img_shape = None

    def InitializeFromMaps(self, lmp: array_t, uid: int) -> None:
        #
        self.uid = uid
        # sites: might contain voxels that could be removed w/o breaking connectivity
        self.sites = (lmp == uid).nonzero()
        self.connection_path = {}
        self.extensions = []
        self.img_shape = lmp.shape

    def ExtendWith(
        self, extension: glial_cmp_t, through: site_path_h, costs: array_t
    ) -> None:
        #
        connection_path = tuple(zip(*through[1:-1]))
        if connection_path.__len__() == 0:
            connection_path = None
        extension_path = extension.sites

        self.connection_path[extension.uid] = connection_path
        self.extensions.append(extension)

        extension.BackReferenceSoma(self)

        # TODO: Ideally, these paths should be dilated
        # but in ext-ext connections, there must not be dilation around the current ext
        # (current ext plays the role of a soma in soma-ext step)
        if connection_path is not None:
            costs[connection_path] = np_.inf
        costs[extension_path] = np_.inf

    def BackReferenceSoma(self, glial_cmp: glial_cmp_t):
        #
        raise NotImplementedError