Esempio n. 1
0
def temporal(in_folder, big_folder, persThresh, consistThresh):
    #find mappers with persistence higher than 1
    #use that list to go through each time slice
    #if more than 50% of the time slices where for the same part of the day - output the mapper and time slices
    B = nx.read_yaml(big_folder)
    users = B.nodes(data=True)
    pers_users = [u[0] for u in users if u[1]['persistence'] > persThresh]
    for u in pers_users:
        night = 0
        day = 0
        evenining = 0
        persistence = 0
        for file in os.listdir(in_folder):
            if file != '.DS_Store':  #weird MAC thing
                path = in_folder + file
                G = getJsonNet(path)
                G = nx.DiGraph(G)
                if G.has_node(u):
                    persistence += 1
                    period = str(file)[11:13]
                    if period == '00':  #03 for the old, wrong time
                        night += 1
                    elif period == '08':  #11 for the old, wrong time
                        day += 1
                    else:
                        evenining += 1
        if night / float(persistence) > consistThresh:
            print u, 'night', night / float(persistence)
        elif day / float(persistence) > consistThresh:
            print u, 'day', day / float(persistence)
        elif evenining / float(persistence) > consistThresh:
            print u, 'evenining', evenining / float(persistence)
def combineSelectSlices(timeList, folder):
	B=nx.DiGraph()
	for slice in timeList:
		path=folder+slice
		G=getJsonNet(path)
		G=nx.DiGraph(G)
		B=composeWeights(B,G)
	return B
Esempio n. 3
0
def spatial_major(in_folder, cliqueThresh):
    for file in os.listdir(in_folder):
        if file != '.DS_Store':  #weird MAC thing
            path = in_folder + file
            G = getJsonNet(path)
            G = nx.Graph(G)  #can't do cliques on directed nets
            if G.order() > 0:
                n = nx.graph_clique_number(G)
                if n > cliqueThresh:
                    print file
                    for c in nx.k_clique_communities(G, n):
                        print list(c)
def findTimeSliceByEdge(edge,folder):
	#folder='/Users/Ish/Documents/OSM_Files/haiti_earthquake/networks14days/overlapping_changesets_by_'+bucket+'_hour/'

	timeList=[]
	for file in os.listdir(folder):
		if file!='.DS_Store': #weird MAC thing
			path=folder+file
			G=getJsonNet(path)
			G=nx.DiGraph(G)
			if edge in set(G.edges()):
				print file
				timeList.append(file)
	return timeList
def combineAll(in_folder, out_folder):
    #expFolder='/Users/Ish/Dropbox/OSM/results/TwoWeeks/overlapping_changesets/ExpAnnotNets/\
    #overlapping_changesets_by_'+bucket+'_hour/'
    B = nx.DiGraph()
    for file in os.listdir(in_folder):
        if file != '.DS_Store':  #weird MAC thing
            path = in_folder + file

            G = getJsonNet(path)
            #G=nx.read_gml(path)
            G = nx.DiGraph(G)
            B = composeWeights(B, G)
    #return B
    nx.write_yaml(B, out_folder)
Esempio n. 6
0
def byNode(user,folder):
	#folder='/Users/Ish/Documents/OSM_Files/haiti_earthquake/networks14days/overlapping_changesets_by_'+bucket+'_hour/'

	timeList=[]
	for file in os.listdir(folder):
		if file!='.DS_Store': #weird MAC thing
			path=folder+file
			G=getJsonNet(path)
			G=nx.DiGraph(G)
			if user in set(G.nodes()):
				print file
				print G.node[user]['weight']
				timeList.append(file)
	return timeList
Esempio n. 7
0
def expand_out3(in_folder, compThresh):  #undirected
    #filling in the puzzle by overlapping with someone else for changeset_overlap
    #building out the road network for intersecting_roads
    for file in os.listdir(in_folder):
        if file != '.DS_Store':  #weird MAC thing
            path = in_folder + file
            G = getJsonNet(path)
            G = nx.Graph(G)  #need long chains - not directed
            if G.order() > 0:
                giant = sorted(nx.connected_components(G),
                               key=len,
                               reverse=True)[0]
                if len(giant) / float(len(G)) > compThresh:
                    print file
                    print "giant: ", giant
                    print "not in giant: ", list(set(G.nodes()) - set(giant))
Esempio n. 8
0
def expand_out(in_folder, diamThresh):
    #filling in the puzzle by overlapping with someone else for changeset_overlap
    #building out the road network for intersecting_roads
    for file in os.listdir(in_folder):
        if file != '.DS_Store':  #weird MAC thing
            path = in_folder + file
            G = getJsonNet(path)
            G = nx.Graph(G)  #need long chains - not directed
            if G.order() > 0:
                giant = sorted(nx.connected_component_subgraphs(G),
                               key=len,
                               reverse=True)[0]
                diam = nx.diameter(giant)
                if diam > diamThresh:
                    print file
                    paths = nx.shortest_path(G)
                    for x in paths.values():
                        for i in xrange(len(x.values())):
                            if len(x.values()[i]) == diam + 1:  #diameter pat
                                print x.values()[i]
Esempio n. 9
0
import networkx as nx
import numpy as np
import os.path
from TimeNetworksAnalytics import getJsonNet

folder = '/Users/Ish/Documents/OSM_Files/philippines/networks14days/'
out_folder = '/Users/Ish/Dropbox/OSM/results/Philippines/TwoWeeks/intersecting_roads/AvgNetStrength/'

for dir in os.listdir(folder):
    av_strength = []
    if dir.startswith('intersecting_roads'):
        #if dir!='.DS_Store':
        for file in os.listdir(folder + dir):
            if file != '.DS_Store':
                path = folder + dir + '/' + file
                G = getJsonNet(path)
                #G=nx.read_gml(path)
                G = nx.Graph(G)
                if len(G) > 0:
                    A = nx.adjacency_matrix(G)
                    strength = A.sum(axis=1)
                    avs = strength.mean()
                else:
                    avs = 0
                av_strength.append(avs)
        np.array(av_strength).tofile(out_folder + dir + '_avgStrength.txt',
                                     sep=',')