Exemplo n.º 1
0
    def loadLabels(self, fname):
        """
        Load the labels file, which may be in JSON or CSV format
        
        The csv file should have the following format
        index,parent_index,data1,data1,dataN\n
        The first line should be a header line. Suggested separators: | or ,

        Header must include at least the name of the area. So we can get, e.g. 
        'name': 'Entorhinal area, lateral part, layer 2'

        The JSON should be the raw JSON from the ARA website

        Returns the labels as a tree structure that can be indexed by ID
        """

        if fname.lower().endswith('.csv'):
            colSep = self.guessFileSep(fname)
            return tree.importData(fname, colSep=colSep, headerLine=True)

        if fname.lower().endswith('.json'):
            (flattened, colNames) = ara_json.importData(fname)
            return tree.importData(flattened.split('\n'),
                                   colSep='|',
                                   headerLine=colNames)
quiet = args.q


if fname is None:
    print "Please supply a file name to convert. e.g.:\nexportedGoggleTree2LasagnaLines.py -f myFile.csv\n"
    sys.exit(0)



#Get the data out of the tree
if os.path.exists(fname) == False:
    print 'Can not find ' + fname
    sys.exit(0)


dataTree = importData(fname,headerLine=['id','parent','z','x','y']) 

#Get the unique segments of each tree
paths=[]
for thisSegment in dataTree.findSegments():
    paths.append(thisSegment)


def dataFromPath(tree,path):
    """
    Get the data from the tree given a path.
    """
    x=[]
    y=[]
    z=[]
    for thisNode in path:
quiet = args.q


if fname is None:
    print("Please supply a file name to convert. e.g.:\nexportedGoggleTree2LasagnaLines.py -f myFile.csv\n")
    sys.exit(0)



#Get the data out of the tree
if os.path.exists(fname) == False:
    print('Can not find ' + fname)
    sys.exit(0)


dataTree = importData(fname,headerLine=['id','parent','z','x','y']) 

#Get the unique segments of each tree
paths=[]
for thisSegment in dataTree.findSegments():
    paths.append(thisSegment)


def dataFromPath(tree,path):
    """
    Get the data from the tree given a path.
    """
    x=[]
    y=[]
    z=[]
    for thisNode in path:
Exemplo n.º 4
0
    def showLoadDialog(self,fname=None):
        """
        This slot brings up the load dialog and retrieves the file name.
        NOTE:
        If a filename is provided then this is loaded and no dialog is brought up.
        If the file name is valid, it loads the base stack using the load method.
        """

        verbose = False 

        if fname is None or not fname:
            fname = self.lasagna.showFileLoadDialog(fileFilter="Text Files (*.txt *.csv)")
    
        if fname is None or not fname:
            return

        if os.path.isfile(fname): 
            with open(str(fname),'r') as fid:

                #import the tree 
                if verbose:
                    print "tree_reader_plugin.showLoadDialog - importing %s" % fname

                dataTree = importData(fname,headerLine=['id','parent','z','x','y'],verbose=verbose)
                if not dataTree:
                    print "No data loaded from %s" % fname
                    return

                #We now have an array of unique paths (segments)
                paths=[]
                for thisSegment in dataTree.findSegments():
                    paths.append(thisSegment)


                ii=0
                asList=[] #list of list data (one item per node)
                for thisPath in paths:
                    data = self.dataFromPath(dataTree,thisPath)
                    for jj in range(len(data[0])):
                        tmp = [ii,data[0][jj],data[1][jj],data[2][jj]]
                        tmp = [float(x) for x in tmp] #convert to floats
                        asList.append(tmp)
                    ii += 1



            # add nans between lineseries
            data=[]
            lastLineSeries=None
            n=0
            for ii in range(len(asList)):
                if len(asList[ii])==0:
                    continue

                thisLine = asList[ii]
                if lastLineSeries is None:
                    lastLineSeries=thisLine[0]

                if lastLineSeries != thisLine[0]:
                    n+=1
                    data.append([np.nan, np.nan, np.nan])

                lastLineSeries=thisLine[0]
                data.append(thisLine[1:])


            if verbose:
                print "Divided tree into %d segments" % n

            #print data         
            objName=fname.split(os.path.sep)[-1]
            self.lasagna.addIngredient(objectName=objName, 
                        kind=self.kind,
                        data=np.asarray(data), 
                        fname=fname,
                        )

            self.lasagna.returnIngredientByName(objName).addToPlots() #Add item to all three 2D plots
            self.lasagna.initialiseAxes()


        else:
            self.lasagna.statusBar.showMessage("Unable to find " + str(fname))
Exemplo n.º 5
0
        atlas_id=obj[u'atlas_id'],
        acronym=obj[u'acronym'],
        name=obj[u'name'],
        color=obj[u'color_hex_triplet'])

    for child in obj.get('children', []):
        flattened = tree_flatten(child, flattened=flattened)

    return flattened


#----------------------------------------------------------------------------
if __name__ == '__main__':
    if len(sys.argv) > 1:
        fname = sys.argv[1]

    (flattened, colNames) = importData(fname)

    returnTree = True

    #Optionally run flattened structure through tree
    if returnTree:
        import tree
        tree.importData(flattened.split('\n'),
                        colSep='|',
                        displayTree=True,
                        headerLine=colNames)

    else:
        print flattened