Ejemplo n.º 1
0
            # Calculate the angle of the current section:
            if parent_section:
                joining_vec = new_section.get_distal_npa3(
                ) - parent_section.get_distal_npa3()
                angle = math.radians(math.atan2(joining_vec[1],
                                                joining_vec[0]))
            section_angles_dict[new_section] = angle

            #Save the section:
            section_dict[yaml_id] = new_section

        # # TODO: THIS IS A HACK! Ensure the dummy node has no attached regions:
        # section_dict[None].regions = []
        assert section_dict[0].region == None

        if section_dict[0].children == []:
            raise ValueError("No segments found")
        morphs = MorphologyTree(name=name,
                                dummysection=section_dict[0],
                                metadata=metadata)
        if len(morphs) < 1:
            raise ValueError
        return morphs


MorphologyImporter.register('fromDictionary',
                            DictionaryLoader.load,
                            allow_override=False,
                            as_type=MorphologyTree)
Ejemplo n.º 2
0
                        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)


MorphologyImporter.register(method_name='fromMorphML',
                            import_functor=MorphMLLoader.load,
                            as_type=MorphologyTree)
Ejemplo n.º 3
0
        lines = [line.strip() for line in src.readlines()]
        lines = [line for line in lines if line and line[0] != '#']

        # Break into sections where we get a new parent:
        splits = [[]]
        for line in lines:

            if int(line.split()[-1]) == -1:
                splits.append([])
            splits[-1].append(line)

        splits = splits[1:]

        data_blocks = ['\n'.join(blk) for blk in splits]
        file_objs = [StringIO(blk) for blk in data_blocks]

        morphs = [cls.load_swc_single(src=fobj) for fobj in file_objs]
        return morphs


# To Array:
MorphologyImporter.register('fromSWC', NewSWCLoader.load_swc_single, as_type=MorphologyArray)

# To Tree:

def _load_swc_single_tree(*args, **kwargs):
    return NewSWCLoader.load_swc_single(*args, **kwargs).to_tree()
MorphologyImporter.register('fromSWC', _load_swc_single_tree,  as_type=MorphologyTree)

Ejemplo n.º 4
0
                    # 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)


MorphologyImporter.register(method_name="fromMorphML", import_functor=MorphMLLoader.load, as_type=MorphologyTree)
            else:
                newSection = Section(x=xyz[0], y=xyz[1], z=xyz[2], r=rad, region=None, idTag=sectionIdTag)
                sectionDict[None] = newSection
            
            
            
                
            # Calculate the angle of the current section:
            if parentSection:
                joiningVec = newSection.getDistalNPA3() - parentSection.getDistalNPA3()
                angle = math.radians(math.atan2(joiningVec[1], joiningVec[0]))
            sectionAnglesDict[newSection] = angle
            
            
            #Save the section:
            sectionDict[yamlID] = newSection   
            
            
        ## TODO: THIS IS A HACK! Ensure the dummy node has no attached regions:
        #sectionDict[None].regions = []
        assert sectionDict[0].region == None 
    
        if sectionDict[0].children == []: raise ValueError("No segments found")
        c = MorphologyTree(name=name, dummysection=sectionDict[0], metadata=metaData)
        if len(c) < 1: raise ValueError
        return c
    
    

MorphologyImporter.register("fromDictionary", DictionaryLoader.Load, allow_override=False, as_type=MorphologyTree)