Ejemplo n.º 1
0
def Test_Histogram(Graph_MD):
    """ Returns histrogram for multi-directinal network graph **Graph_MD**.
    
    \n.. comments:
    Input:
        Graph_MD        Instance of NX multi-directinal graph
    Return:
        HistSegmKnoten  Vektor, mit Werten
    
    """

    Edges = NX.edges(Graph_MD)
    KnotenNamen = NX.nodes(Graph_MD)

    KnotenNamenListe = M_Helfer.unique_String(KnotenNamen)
    NumKnotenListe = len(KnotenNamenListe)
    KnotenLeitung = arr.array('i', list(range(1, NumKnotenListe + 1)))

    count = 0
    for Knoten in KnotenLeitung:
        KnotenLeitung[count] = 0
        count = count + 1

    for ii in list(range(NumKnotenListe)):
        KnotenName = KnotenNamenListe[ii]
        for edge in Edges:
            posS = edge[0] == KnotenName
            posE = edge[1] == KnotenName

            if posS:
                KnotenLeitung[ii] = KnotenLeitung[ii] + 1
            if posE:
                KnotenLeitung[ii] = KnotenLeitung[ii] + 1

    MaxKnotenLeitung = max(KnotenLeitung)
    HistSegmKnoten = M_MatLab.zeros('i', MaxKnotenLeitung + 1)

    for ii in list(range(0, MaxKnotenLeitung + 1)):
        HistSegmKnoten[ii] = len(
            M_FindPos.find_pos_ValInVector(ii, KnotenLeitung, '=='))

    return HistSegmKnoten
Ejemplo n.º 2
0
def sort_Vector(vecIn):
    """ Sorting a list of values
    
    \n.. comments: 
    Input:
        vecIn:       list of floats/int
    Output:
        RetList:      list of sorted values
        PosList:      list of Positions
    """

    vecin = copy.deepcopy(vecIn)

    PosList = []
    ReTransform = False
    if isinstance(vecin[0], int):
        ReTransform = True
        for ii in range(len(vecin)):
            vecin[ii] = float(vecin[ii])

    # Sorting data
    RetList = sorted([x for x in vecin if not math.isnan(x)], reverse=False)

    # determen position values
    for ii in range(len(RetList)):
        pos = M_FindPos.find_pos_ValInVector(RetList[ii], vecin, '==')
        PosList.append(pos[0])
        vecin[pos[0]] = np.inf

    # Transform back to Int if required
    if ReTransform == True:
        for ii in range(len(RetList)):
            RetList[ii] = int(RetList[ii])

    else:
        print('ERROR: M_MatLab.sort_Vector: code not written yet')

    return RetList, PosList
Ejemplo n.º 3
0
def fixPipeSegmentsNode(PipeSegments, Nodes):
    """ Fixing wrong Start_point and End_Point id in respect of lat long

    \n.. comments: 
    Input:
        PipeSegments:   List of PipeSegments
        Nodes:          List of Nodes
    Return:
        PipeSegments
    """    
    
    node_id     = []
    node_lat    = []
    node_long   = []
    count       = 0
#    sourceIDNotSwapt = []
#    sourceIDSwapt = []
    
    # Getting Node Id, lat and long of nodes
    for nod in Nodes:
        node_id.append(nod.id)
        node_lat.append(round(nod.lat, roundNum))
        node_long.append(round(nod.long, roundNum))
    
    
    # Checking of there is a node in twice
    for id in node_id:
        pos     = M_FindPos.find_pos_ValInVector(id, node_id, '==')
        if len(pos) != 1:
            print('node ' + str(id) + ' funny.  Found ' + str(len(pos)))

    
    # going through each PipeSegment, and finding corresponding Nodes lat Long values 
    # and checking if they are same with Pipe Lat LONGS
    for pipe in PipeSegments:
        S_pipe_node_id = copy.deepcopy(pipe.node_id[0])
        S_lat     = round(pipe.lat[0], roundNum)
        S_long    = round(pipe.long[0], roundNum)
        
        E_pipe_node_id = copy.deepcopy(pipe.node_id[1])
        E_lat     = round(pipe.lat[-1], roundNum)
        E_long    = round(pipe.long[-1], roundNum)
        
        S_pos     = M_FindPos.find_pos_ValInVector(S_pipe_node_id, node_id, '==')
        E_pos     = M_FindPos.find_pos_ValInVector(E_pipe_node_id, node_id, '==')
        

        if node_lat[S_pos[0]] != S_lat or node_long[S_pos[0]] != S_long:
            if len(S_pos) != 1:
                print('Warning: Start Node Multiple times ' + str(S_pipe_node_id))
            elif len(S_pos) != 1:
                print('Warning: End Node Multiple times ' + str(E_pipe_node_id))
            elif node_lat[S_pos[0]] == E_lat and  node_long[S_pos[0]] == E_long and node_lat[E_pos[0]] == S_lat and  node_long[E_pos[0]] == S_long:
                pipe.node_id = [E_pipe_node_id, S_pipe_node_id]
                count = count + 1
            else:
                print('Warning: still wrong start ' + str(S_pipe_node_id))
    
#    if count > 0:
#        print('needed to rotate ' + str(count) + ' pipelines')
    
    return PipeSegments