Ejemplo n.º 1
0
    def areaVSrelength(addressTop, addressBot, victimCells):
        condition = [True, True, True, True]
        preCelltop = XMLinterpreter(addressTop)
        Celltop = CellCointainer(preCelltop, condition)
        Nodestop= Celltop.allNodesExtract(0)

        preCellbot = XMLinterpreter(addressBot)
        Cellbot = CellCointainer(preCellbot, condition)
        Nodesbot= Cellbot.allNodesExtract(0)
        
        coef = Transformation.getPlaneCoef2(Nodestop)
        
        Nodestop = Transformation.convertCoord(coef, Nodestop)
        Nodesbot = Transformation.convertCoord(coef, Nodesbot)
        
        topX = Transformation.getAvgPoint(Nodestop)[2]
        botX = Transformation.getAvgPoint(Nodesbot)[2]
        

        
        preCellvic = XMLinterpreter(victimCells)
        Cellvic = CellCointainer(preCellvic, condition)
        
        Nodesvic= Cellvic.commentWithKeywordExtractDict("utput") #dictionary// smaller
        print Nodesvic
        #Nodesvic = Cellvic.Nodes
        NodesvicAid = Cellvic.Nodes
        
        DicNodesVCells = {}
        DicNodesVaidCells = {}
        DicNodesError = {}
        ells = [] 
               
        for item1 in Nodesvic.keys():
            DicNodesVCells.setdefault(item1)
            
            temp1 = Transformation.convertCoord(coef, Nodesvic[item1])
            
            #temp1 = Transformation.convertCoord(coef, Transformation.cutCell2(Nodesvic[item2], 0.25, 0.75))
            
            cellcorX = Transformation.getAvgPoint(temp1)[2]
            Relength2 = (topX - cellcorX)/(topX - botX)
            DicNodesVCells[item1] = Relength2
            
            DicNodesError.setdefault(item1)
            
            stdev = Transformation.stdev1D(temp1)
            stdev = stdev/(topX-botX)
            DicNodesError[item1] = stdev
            
            
            
            DicNodesVaidCells.setdefault(item1)
            temp2 = Transformation.convertCoord(coef, NodesvicAid[item1])
            #temp2 = temp1
            
            aEllipse = Covariance.toEllipse(temp2)
            DicNodesVaidCells[item1] = CONF95 * pi * aEllipse[2] * aEllipse[3]
            
            #if DicNodesVCells[item1] < 1.2:
            #    continue #showing mosaic bigger than 1.15            
            

            aEllipse = Covariance.toEllipse(temp2)
            
            #output [ycor zcor Principle1 Principle2 Angle cellname]
           
            temparr = []            
            
            xcordz = aEllipse[0]
            ycordz = aEllipse[1]
            widthz = aEllipse[2] * 2 * math.sqrt(CONF95) #
            heightz = aEllipse[3] * 2 * math.sqrt(CONF95)  #  
            anglez = aEllipse[4]
            
            xyz = []
            xyz.append(xcordz)
            xyz.append(ycordz)
            
            
            
            temparr.append(Ellipse(xy =xyz, width =widthz, height= heightz, angle = anglez * 180/ pi )) 
            temparr.append(xyz)
            temparr.append(item1)
            ells.append(temparr)            
        """        
        ## del ##
        
        DicNodesVCells.setdefault("top")
             
        cellcorX = Transformation.getAvgPoint(Nodestop)[2]
        Relength2 = (topX - cellcorX)/(topX - botX)
        DicNodesVCells["top"] = Relength2
            
        DicNodesError.setdefault("top")
            
        stdev = Transformation.stdev1D(Nodestop)
        stdev = stdev/(topX-botX)
        DicNodesError["top"] = stdev
            
            
            
        DicNodesVaidCells.setdefault("top")
        temp2 = Transformation.convertCoord(coef, Nodestop)
            #temp2 = temp1
            
        aEllipse = Covariance.toEllipse(temp2)
        DicNodesVaidCells["top"] = CONF95 * pi * aEllipse[2] * aEllipse[3]
        



        DicNodesVCells.setdefault("bot")
             
        cellcorX = Transformation.getAvgPoint(Nodesbot)[2]
        Relength2 = (topX - cellcorX)/(topX - botX)
        DicNodesVCells["bot"] = Relength2
            
        DicNodesError.setdefault("bot")
            
        stdev = Transformation.stdev1D(Nodesbot)
        stdev = stdev/(topX-botX)
        DicNodesError["bot"] = stdev
            
            
            
        DicNodesVaidCells.setdefault("bot")
        temp2 = Transformation.convertCoord(coef, Nodesbot)
            #temp2 = temp1
            
        aEllipse = Covariance.toEllipse(temp2)
        DicNodesVaidCells["bot"] = CONF95 * pi * aEllipse[2] * aEllipse[3]
        
        """     
        
        ####
        """
        for item4 in DicNodesVCells.keys():
            #if DicNodesVCells[item4] > 1.0:
            #    continue
            
            
            plt.scatter( DicNodesVCells[item4], DicNodesVaidCells[item4], color = Transformation.color(0.8,DicNodesError[item4]), s = 130 )
            
            plt.text(DicNodesVCells[item4], DicNodesVaidCells[item4], item4, ha="center", family='sans-serif', size=10)
            #plt.errorbar(DicNodesVCells[item4], DicNodesVaidCells[item4], xerr = DicNodesError[item4], linestyle = "None", ecolor = Transformation.color(0.8,DicNodesError[item4]))
        show()
        """
        
        

        ###             
        """
            
        fig = figure()
        ax = fig.add_subplot(111, aspect='equal')
        
        
        for e in ells:
            print e
            ax.add_artist(e[0])
            e[0].set_clip_box(ax.bbox)
            e[0].set_alpha(0.3)
            e[0].set_facecolor(Transformation.color(0.8 ,DicNodesError[e[2]]))
            plt.text(e[1][0], e[1][1], e[2], ha="center", family='sans-serif', size=14)
            
        
        ax.set_xlim(-300000,300000)
        ax.set_ylim(-300000,300000)
        show()
        """
#############convex haul###########################################    
    
        ells1 = []
        for item2 in DicNodesVCells.keys():

            
            #if DicNodesVCells[item2] < 1.2:
            #    continue #showing mosaic bigger than 1.15
## 
            newNode = []
            
            DicNodesVCells.setdefault(item2)
            
            temp1 = Transformation.convertCoord(coef, Nodesvic[item2])
            

            
            cellcorX = Transformation.getAvgPoint(temp1)[2]
            Relength2 = (topX - cellcorX)/(topX - botX)
            DicNodesVCells[item2] = Relength2
            
            DicNodesError.setdefault(item2)
            
            stdev = Transformation.stdev1D(temp1)
            stdev = stdev/(topX-botX)
            DicNodesError[item2] = stdev
            
            
            
            DicNodesVaidCells.setdefault(item2)
            temp2 = Transformation.convertCoord(coef, NodesvicAid[item2])
            #print Transformation.yzExtract(temp2)
            hull = ConvexHull(Transformation.yzExtract(temp2))
            
            newNode.append(hull)
            newNode.append(item2)
            newNode.append(Transformation.yzExtract(temp2))
            ells1.append(newNode)
            
        
            
        fig = figure()
        ax = fig.add_subplot(111, aspect='equal')
        
        for e in ells:
            
            #ax.add_artist(e[0])
            #e[0].set_clip_box(ax.bbox)
            #e[0].set_alpha(0.2)
            #e[0].set_facecolor(Transformation.color(0.8 ,DicNodesError[e[2]]))
            plt.text(e[1][0], e[1][1], e[2], ha="center", family='sans-serif', size=14)
                 
        
        
        
        for arr in ells1:
            
            points = arr[2]
            hull = arr[0]

            
            for vertex in hull.simplices:
 
                plt.plot([(points[(vertex[0])])[0], (points[(vertex[1])])[0]], [(points[(vertex[0])])[1],(points[(vertex[1])])[1]], c =Transformation.color(0.8 ,DicNodesError[arr[1]]) )
            
            
            #convex_hull_plot_2d(arr[0], ax)
        
        i = 0
        
        while i < (len(ells1) - 1):
            fIndex = i
            sIndex = i-1
            
            first = Transformation.verticesToPoints(ells1[fIndex][0], ells1[fIndex][2])
            second = Transformation.verticesToPoints(ells1[sIndex][0], ells1[sIndex][2])
            
            
            i = i + 1
            
            collidng = Transformation.ClipPolygon(first, second)
            for item in collidng:
                 plt.scatter( item[0], item[1], s = 130 )
        
        
        ax.set_xlim(-300000,300000)
        ax.set_ylim(-300000,300000)
        show()