コード例 #1
0
    def getitem(self, *args, **kwargs):

        assert len(kwargs) == 1
        k = kwargs.keys()[0]
        v = kwargs[k]

        assert len(args) == 0
        if isinstance(k, collections.Callable):
            return SeqUtils.expect_single([k(o) for o in self.data])

        elif isinstance(k, basestring):
            return SeqUtils.expect_single([o for o in self.data if getattr(o, k) == v])
        else:
            print "Unexpected Type of %s - %s" % (k, type(k))
            assert False
コード例 #2
0
    def getitem(self, *args, **kwargs):

        assert len(kwargs) == 1
        k = kwargs.keys()[0]
        v = kwargs[k]

        assert len(args) == 0
        if isinstance(k, collections.Callable):
            return SeqUtils.expect_single([k(o) for o in self.data])

        elif isinstance(k, basestring):
            return SeqUtils.expect_single(
                [o for o in self.data if getattr(o, k) == v])
        else:
            print 'Unexpected Type of %s - %s' % (k, type(k))
            assert False
コード例 #3
0
ファイル: simulation.py プロジェクト: NeuroArchive/morphforge
    def get_cell(self, cellname=None):
        """ Either return a cell by name if there is more than one cell, otherwise the single cell """

        if cellname:
            return SeqUtils.filter_expect_single(self.cells,
                    lambda s: s.name == cellname)
        else:
            return SeqUtils.expect_single(self.cells)
コード例 #4
0
    def get_cell(self, cellname=None):
        """ Either return a cell by name if there is more than one cell, otherwise the single cell """

        if cellname:
            return SeqUtils.filter_expect_single(self.cells,
                                                 lambda s: s.name == cellname)
        else:
            return SeqUtils.expect_single(self.cells)
コード例 #5
0
def buildPaneFromExistingChannelInfTau1State(existing_channel_functor, sim_config, chlname):


    # Setup the channel, so we can look at inf_tau:
    chl =  existing_channel_functor(NEURONEnvironment())

    state_name = SeqUtils.expect_single(chl.statevars.keys())

    state=buildStatePane(chl, state_name)
    general=HHGeneralPanel(
            gbar=float(chl.conductance.rescale('mS/cm2').magnitude),
            vrev=float(chl.reversalpotential.rescale("mV").magnitude)
           )


    return  HHChannelPaneInfTau1(sim_config=sim_config,
                                 general_pane=general,
                                 state_pane=state,
                                 eqn = chl.eqn,
                                 state_var_name = state_name,
                                 chlname = chlname
                               )
コード例 #6
0
    def load_cell_dictionaries(self, cellNode, regions=None):

        l1 = Level1NeuroMLRepresentation(cellNode)

        print 'CellName:', cellNode.getAttribute('name')

        # We are not too worried about cables, but we do need the region name out of them:
        cableIDToRegionName = {}
        cablesNode = SeqUtils.filter_expect_single(cellNode.childNodes,
                                                   isElementWithTag("cables"))
        for cableNode in Filter(cablesNode.childNodes,
                                isElementWithTag("cable")):
            id = cableNode.getAttribute("id")
            name = cableNode.getAttribute("name")

            group_nodes = Filter(cableNode.childNodes,
                                 isElementWithTag("group"))

            if group_nodes:
                if regions:
                    metaGroupNode = SeqUtils.filter_expect_single(
                        group_nodes, lambda e: get_text(e) in regions)
                    region_name = regions[get_text(metaGroupNode)]
                else:
                    metaGroupNode = SeqUtils.expect_single(group_nodes)
                    region_name = get_text(metaGroupNode)

                assert not id in cableIDToRegionName
                cableIDToRegionName[id] = region_name

            else:
                cableIDToRegionName[id] = None
                pass

            print 'Loaded Cable: ', id, name

        # Load the segments:
        segmentListInfo = {
        }  # id -> (id, name, cable, parent, (px, py, pz, pDiam), (dx, dy, dz, dDiam))
        segmentsNode = SeqUtils.filter_expect_single(
            cellNode.childNodes, isElementWithTag("segments"))
        for segNode in Filter(segmentsNode.childNodes,
                              isElementWithTag("segment")):
            print "Segment"
            id = segNode.getAttribute("id")
            name = segNode.getAttribute("name")
            cable = segNode.getAttribute("cable")
            parent = segNode.getAttribute("parent")

            # Every point should have a distal End:
            dNode = SeqUtils.filter_expect_single(segNode.childNodes,
                                                  isElementWithTag("distal"))
            d_x, d_y, d_z = dNode.getAttribute("x"), dNode.getAttribute(
                "y"), dNode.getAttribute("z")
            d_diam = dNode.getAttribute("diameter")

            if not parent:
                pass
                pNode = SeqUtils.filter_expect_single(
                    segNode.childNodes, isElementWithTag("proximal"))
                p_x, p_y, p_z = pNode.getAttribute("x"), pNode.getAttribute(
                    "y"), pNode.getAttribute("z")
                p_diam = pNode.getAttribute("diameter")

            else:
                # Not every point need have a proximal end, we look at the parent in case it has
                # both and check the locations agree
                parent_Dist_Loc = segmentListInfo[parent][5]

                pNode = Filter(segNode.childNodes,
                               isElementWithTag("proximal"))
                if len(pNode) == 0:
                    p_x, p_y, p_z, p_diam = parent_Dist_Loc

                elif len(pNode) == 1:
                    p_xR, p_yR, p_zR = pNode[0].getAttribute("x"), pNode[
                        0].getAttribute("y"), pNode[0].getAttribute("z")
                    p_diamR = pNode[0].getAttribute("diameter")

                    # I do not understand MorphML to understand why these checks do not fail....
                    #print (p_xR, p_yR, p_zR)
                    #print (parent_Dist_Loc[0], parent_Dist_Loc[1], parent_Dist_Loc[2])
                    #assert (p_xR, p_yR, p_zR) == (parent_Dist_Loc[0], parent_Dist_Loc[1], parent_Dist_Loc[2])
                    # In this case, use the diameter just read:
                    p_x, p_y, p_z = p_xR, p_yR, p_zR
                    p_diam = p_diamR

                else:

                    assert False

            print id, name, cable, parent, (p_x, p_y, p_z,
                                            p_diam), (d_x, d_y, d_z, d_diam)
            infTuple = (id, name, cable, parent, (float(p_x), float(p_y),
                                                  float(p_z), float(p_diam)),
                        (float(d_x), float(d_y), float(d_z), float(d_diam)))
            assert not id in segmentListInfo
            segmentListInfo[id] = infTuple

        # Now we have read the file and created the dictionaries:
        return (cableIDToRegionName, segmentListInfo)
コード例 #7
0
    def __init__(self, cellNode):

        self.cables = SearchableSet()
        self.cablegroups = SearchableSet()
        self.segments = SearchableSet()

        # Read the XML:

        # Start with the declared Cables:
        cablesNode = FilterExpectSingleChildrenByTag(cellNode, 'cables')

        # Load the individual cable objects
        for cableNode in FilterChildrenByTag(cablesNode, "cable"):
            if cableNode.getAttribute('id') in self.cables.keys('cable_id'):
                continue

            cable = NeuroMLCable(cable_id=cableNode.getAttribute('id'),
                                 name=cablesNode.getAttribute('name'))
            self.cables.add(cable)

            # Does the cable belong to any groups?
            for group_node in Filter(cableNode.childNodes,
                                     isElementWithTag("group")):
                cablegroupname = get_text(group_node)
                if not cablegroupname in self.cablegroups.keys('name'):
                    self.cablegroups.add(
                        NeuroMLCableGroup(name=cablegroupname))
                self.cablegroups.getitem(name=cablegroupname).add_cable(cable)

        # Load the CableGroup Objects:
        for cableGroupNode in Filter(cablesNode.childNodes,
                                     isElementWithTag("cablegroup")):

            # Get, or create, the cable node:
            cablegroupname = cableGroupNode.getAttribute('name')
            if not cablegroupname in self.cablegroups.keys('name'):
                self.cablegroups.add(NeuroMLCableGroup(name=cablegroupname))
            grp = self.cablegroups.getitem(name=cablegroupname)

            # Add the cable segments:
            for cableNode in Filter(cableGroupNode.childNodes,
                                    isElementWithTag("cable")):
                cableNodeID = cableNode.getAttribute('id')
                if not cableNodeID in self.cables.keys('cable_id'):
                    assert False
                cable = self.cables.getitem(cable_id=cableNodeID)
                grp.add_cable(cable)

        # Load the Segments Objects:
        segmentsNode = SeqUtils.filter_expect_single(
            cellNode.childNodes, isElementWithTag("segments"))
        for segmentNode in Filter(segmentsNode.childNodes,
                                  isElementWithTag("segment")):

            #Attributes:
            segment_id = segmentNode.getAttribute('id')
            parent_id = segmentNode.getAttribute('parent')
            cable_id = segmentNode.getAttribute('cable')
            cable = self.cables.getitem(
                cable_id=cable_id) if cable_id else None

            # Distal Information:
            distalNode = FilterExpectSingleChildrenByTag(segmentNode, 'distal')
            d_X, d_Y, d_Z, d_d = float(distalNode.getAttribute('x')), float(
                distalNode.getAttribute('y')), float(
                    distalNode.getAttribute('z')), float(
                        distalNode.getAttribute('diameter'))
            dInfo = (d_X, d_Y, d_Z, d_d)

            proximalNode = FilterChildrenByTag(segmentNode, 'proximal')

            # Root node:
            if not parent_id:
                assert proximalNode
                proximalNode = SeqUtils.expect_single(proximalNode)
                p_X, p_Y, p_Z, p_d = float(
                    proximalNode.getAttribute('x')), float(
                        proximalNode.getAttribute('y')), float(
                            proximalNode.getAttribute('z')), float(
                                proximalNode.getAttribute('diameter'))
                pInfo = (p_X, p_Y, p_Z, p_d)
                segment = NeuroMLSegment(segment_id=segment_id,
                                         distInfo=dInfo,
                                         proxInfo=pInfo,
                                         parent=None,
                                         cable=cable)

            #Child Node:
            else:

                # Not the root node, but a proximal node is provided:
                if proximalNode:

                    pInfo = (p_X, p_Y, p_Z, p_d)

                    # Proximal node and NOT the root:
                    if parent_id:
                        parentNode = self.segments.getitem(
                            segment_id=parent_id)
                        parentDistalInfo = parentNode.distInfo
                        eps = 0.01
                        # assert fabs(parentDistalInfo[0] - pInfo[0]) < eps
                        # assert fabs(parentDistalInfo[1] - pInfo[1]) < eps
                        # assert fabs(parentDistalInfo[2] - pInfo[2]) < eps
                        # assert fabs(parentDistalInfo[3] - pInfo[3]) < eps

                # Add the child node:
                segment = NeuroMLSegment(segment_id=segment_id,
                                         distInfo=dInfo,
                                         proxInfo=pInfo,
                                         parent=None,
                                         cable=cable)

            # Add the segment to groups?
            self.segments.add(segment)
コード例 #8
0
    def load_cell_dictionaries(self, cellNode, regions=None):

        l1 = Level1NeuroMLRepresentation(cellNode)

        print "CellName:", cellNode.getAttribute("name")

        # We are not too worried about cables, but we do need the region name out of them:
        cableIDToRegionName = {}
        cablesNode = SeqUtils.filter_expect_single(cellNode.childNodes, isElementWithTag("cables"))
        for cableNode in Filter(cablesNode.childNodes, isElementWithTag("cable")):
            id = cableNode.getAttribute("id")
            name = cableNode.getAttribute("name")

            group_nodes = Filter(cableNode.childNodes, isElementWithTag("group"))

            if group_nodes:
                if regions:
                    # for n in group_nodes:
                    #    print get_text(n)
                    metaGroupNode = SeqUtils.filter_expect_single(group_nodes, lambda e: get_text(e) in regions)
                    region_name = regions[get_text(metaGroupNode)]
                else:
                    metaGroupNode = SeqUtils.expect_single(group_nodes)
                    region_name = get_text(metaGroupNode)

                assert not id in cableIDToRegionName
                cableIDToRegionName[id] = region_name

            else:
                cableIDToRegionName[id] = None
                pass

            print "Loaded Cable: ", id, name

        # Load the segments:
        segmentListInfo = {}  # id -> (id, name, cable, parent, (px, py, pz, pDiam), (dx, dy, dz, dDiam))
        segmentsNode = SeqUtils.filter_expect_single(cellNode.childNodes, isElementWithTag("segments"))
        for segNode in Filter(segmentsNode.childNodes, isElementWithTag("segment")):
            print "Segment"
            id = segNode.getAttribute("id")
            name = segNode.getAttribute("name")
            cable = segNode.getAttribute("cable")
            parent = segNode.getAttribute("parent")

            # Every point should have a distal End:
            dNode = SeqUtils.filter_expect_single(segNode.childNodes, isElementWithTag("distal"))
            d_x, d_y, d_z = dNode.getAttribute("x"), dNode.getAttribute("y"), dNode.getAttribute("z")
            d_diam = dNode.getAttribute("diameter")

            if not parent:
                pass
                pNode = SeqUtils.filter_expect_single(segNode.childNodes, isElementWithTag("proximal"))
                p_x, p_y, p_z = pNode.getAttribute("x"), pNode.getAttribute("y"), pNode.getAttribute("z")
                p_diam = pNode.getAttribute("diameter")

            else:
                # Not every point need have a proximal end, we look at the parent in case it has
                # both and check the locations agree
                parent_Dist_Loc = segmentListInfo[parent][5]

                pNode = Filter(segNode.childNodes, isElementWithTag("proximal"))
                if len(pNode) == 0:
                    p_x, p_y, p_z, p_diam = parent_Dist_Loc

                elif len(pNode) == 1:
                    p_xR, p_yR, p_zR = (
                        pNode[0].getAttribute("x"),
                        pNode[0].getAttribute("y"),
                        pNode[0].getAttribute("z"),
                    )
                    p_diamR = pNode[0].getAttribute("diameter")

                    # I do not understand MorphML to understand why these checks do not fail....
                    # print (p_xR, p_yR, p_zR)
                    # print (parent_Dist_Loc[0], parent_Dist_Loc[1], parent_Dist_Loc[2])
                    # assert (p_xR, p_yR, p_zR) == (parent_Dist_Loc[0], parent_Dist_Loc[1], parent_Dist_Loc[2])
                    # In this case, use the diameter just read:
                    p_x, p_y, p_z = p_xR, p_yR, p_zR
                    p_diam = p_diamR

                else:

                    assert False

            print id, name, cable, parent, (p_x, p_y, p_z, p_diam), (d_x, d_y, d_z, d_diam)
            infTuple = (
                id,
                name,
                cable,
                parent,
                (float(p_x), float(p_y), float(p_z), float(p_diam)),
                (float(d_x), float(d_y), float(d_z), float(d_diam)),
            )
            assert not id in segmentListInfo
            segmentListInfo[id] = infTuple

        # Now we have read the file and created the dictionaries:
        return (cableIDToRegionName, segmentListInfo)
コード例 #9
0
    def __init__(self, cellNode):

        self.cables = SearchableSet()
        self.cablegroups = SearchableSet()
        self.segments = SearchableSet()

        # Read the XML:

        # Start with the declared Cables:
        cablesNode = FilterExpectSingleChildrenByTag(cellNode, "cables")

        # Load the individual cable objects
        for cableNode in FilterChildrenByTag(cablesNode, "cable"):
            if cableNode.getAttribute("id") in self.cables.keys("cable_id"):
                continue

            cable = NeuroMLCable(cable_id=cableNode.getAttribute("id"), name=cablesNode.getAttribute("name"))
            self.cables.add(cable)

            # Does the cable belong to any groups?
            for group_node in Filter(cableNode.childNodes, isElementWithTag("group")):
                cablegroupname = get_text(group_node)
                if not cablegroupname in self.cablegroups.keys("name"):
                    self.cablegroups.add(NeuroMLCableGroup(name=cablegroupname))
                self.cablegroups.getitem(name=cablegroupname).add_cable(cable)

        # Load the CableGroup Objects:
        for cableGroupNode in Filter(cablesNode.childNodes, isElementWithTag("cablegroup")):

            # Get, or create, the cable node:
            cablegroupname = cableGroupNode.getAttribute("name")
            if not cablegroupname in self.cablegroups.keys("name"):
                self.cablegroups.add(NeuroMLCableGroup(name=cablegroupname))
            grp = self.cablegroups.getitem(name=cablegroupname)

            # Add the cable segments:
            for cableNode in Filter(cableGroupNode.childNodes, isElementWithTag("cable")):
                cableNodeID = cableNode.getAttribute("id")
                if not cableNodeID in self.cables.keys("cable_id"):
                    assert False
                cable = self.cables.getitem(cable_id=cableNodeID)
                grp.add_cable(cable)

        # Load the Segments Objects:
        segmentsNode = SeqUtils.filter_expect_single(cellNode.childNodes, isElementWithTag("segments"))
        for segmentNode in Filter(segmentsNode.childNodes, isElementWithTag("segment")):

            # Attributes:
            segment_id = segmentNode.getAttribute("id")
            parent_id = segmentNode.getAttribute("parent")
            cable_id = segmentNode.getAttribute("cable")
            cable = self.cables.getitem(cable_id=cable_id) if cable_id else None

            # Distal Information:
            distalNode = FilterExpectSingleChildrenByTag(segmentNode, "distal")
            d_X, d_Y, d_Z, d_d = (
                float(distalNode.getAttribute("x")),
                float(distalNode.getAttribute("y")),
                float(distalNode.getAttribute("z")),
                float(distalNode.getAttribute("diameter")),
            )
            dInfo = (d_X, d_Y, d_Z, d_d)

            proximalNode = FilterChildrenByTag(segmentNode, "proximal")

            # Root node:
            if not parent_id:
                assert proximalNode
                proximalNode = SeqUtils.expect_single(proximalNode)
                p_X, p_Y, p_Z, p_d = (
                    float(proximalNode.getAttribute("x")),
                    float(proximalNode.getAttribute("y")),
                    float(proximalNode.getAttribute("z")),
                    float(proximalNode.getAttribute("diameter")),
                )
                pInfo = (p_X, p_Y, p_Z, p_d)
                segment = NeuroMLSegment(
                    segment_id=segment_id, distInfo=dInfo, proxInfo=pInfo, parent=None, cable=cable
                )

            # Child Node:
            else:

                # Not the root node, but a proximal node is provided:
                if proximalNode:

                    pInfo = (p_X, p_Y, p_Z, p_d)

                    # Proximal node and NOT the root:
                    if parent_id:
                        parentNode = self.segments.getitem(segment_id=parent_id)
                        parentDistalInfo = parentNode.distInfo
                        eps = 0.01
                        # assert fabs(parentDistalInfo[0] - pInfo[0]) < eps
                        # assert fabs(parentDistalInfo[1] - pInfo[1]) < eps
                        # assert fabs(parentDistalInfo[2] - pInfo[2]) < eps
                        # assert fabs(parentDistalInfo[3] - pInfo[3]) < eps

                # Add the child node:
                segment = NeuroMLSegment(
                    segment_id=segment_id, distInfo=dInfo, proxInfo=pInfo, parent=None, cable=cable
                )

            # Add the segment to groups?
            self.segments.add(segment)