コード例 #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)
コード例 #2
0
from morphforge.morphology.core.morphologyarray import MorphologyArray

from morphforge.morphology.core.morphologytree import MorphologyTree
from morphforge.morphology.ui.mayavirenderer import MayaViRenderer
from morphforge.morphology.ui.matplotlibviewer import MatPlotLibViewer
from morphforge.morphology.importer.morphologyimporter import MorphologyImporter
from morphforge.morphology.exporter.morphologyexporter import MorphologyExporter
from morphforge.morphology.comparison.comparearrays import MorphArrayComparison
from morphforge.morphology.builders.morphologyloader import MorphologyLoader






m = MorphologyImporter.fromSWCFile(filename="/home/michael/workspace/morphforge/src/test_data/swc_srcs/28o_spindle20aFI.CNG.swc", astype=MorphologyTree)


MorphologyExporter.toSWCFile(morphology = m, filename="/home/michael/Desktop/test1.swc")

m2 = MorphologyImporter.fromSWCFile(filename="/home/michael/Desktop/test1.swc", astype=MorphologyTree)



#m2 = MorphologyLoader.fromSWC(src=open("/home/michael/workspace/morphforge/src/test_data/swc_srcs/28o_spindle20aFI.CNG.swc"))





コード例 #3
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)
コード例 #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)
コード例 #5
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)

コード例 #6
0
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------

from morphforge.morphology.core.morphologyarray import MorphologyArray

from morphforge.morphology.core.morphologytree import MorphologyTree
from morphforge.morphology.ui.mayavirenderer import MayaViRenderer
from morphforge.morphology.ui.matplotlibviewer import MatPlotLibViewer
from morphforge.morphology.importer.morphologyimporter import MorphologyImporter
from morphforge.morphology.exporter.morphologyexporter import MorphologyExporter
from morphforge.morphology.comparison.comparearrays import MorphArrayComparison
from morphforge.morphology.builders.morphologyloader import MorphologyLoader

m = MorphologyImporter.fromSWCFile(
    filename=
    "/home/michael/workspace/morphforge/src/test_data/swc_srcs/28o_spindle20aFI.CNG.swc",
    astype=MorphologyTree)

MorphologyExporter.toSWCFile(morphology=m,
                             filename="/home/michael/Desktop/test1.swc")

m2 = MorphologyImporter.fromSWCFile(filename="/home/michael/Desktop/test1.swc",
                                    astype=MorphologyTree)

#m2 = MorphologyLoader.fromSWC(src=open("/home/michael/workspace/morphforge/src/test_data/swc_srcs/28o_spindle20aFI.CNG.swc"))

are_same = MorphArrayComparison.are_same(m, m2)
print are_same

#m = MorphologyLoader2.loadSWCFile(filename="/home/michael/workspace/morphforge/src/test_data/swc_srcs/05b_pyramidal9aACC.CNG_short.swc", astype=MorphologyTree)
コード例 #7
0
            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)