示例#1
0
import random as rd
import pylab as pl
import mpl_toolkits.basemap as bm

from numpy import sqrt
#import community as cm

#New Modules
sys.path.append('/Users/Eyota/projects/thesis/code/python/modules')
from rowtodict import *
from drawnetworks import netplot
from importnetworks import importnetwork
import com2 as cm

os.chdir("/Users/Eyota/projects/thesis")

year = '0910'
width = 4700000
height = 3100000

metros, mg, nodedata = importnetwork(year)


#formal communities based on redoing com detection on 100-runs
comsform = pd.io.parsers.read_csv('output/comsformal.csv')
comsform.set_index('id',inplace = True)
comsform = comsform[['pop','lat','lon','MSAName','formalcom']]

comsformdict = comsform['formalcom'].to_dict()
print cm.modularity(comsformdict, mg)
示例#2
0

nx.draw(mgdraw, pos,with_labels = False,alpha = 1, linewidths = 0.5, width = 0,
    nodelist = list(comsdraw.sort(['pop']).index),node_size = 40, node_color = comsdraw.sort(['pop'])['com'])

'''

comnet = nx.Graph()
comnet.add_nodes_from(nodedata)

comsdraw = coms[(metros['lon'] < -60) & (metros['lon'] >-125)]
comlist = []
modularities = []
for i in range(100):
    partition = cm.best_partition(mg)
    modularities.append(cm.modularity(partition, mg))
    #I think it's ok to use the full network including AKHI
    comsdraw = dict2column(comsdraw, partition,'com%s'%i)
    #'part%s' %i)
    netplot('output/commaps/maps_com_%s_%s.jpeg'%(i,year),width, height, mgdraw,pos,with_labels = False,alpha = 1, linewidths = 0.5, width = 0,
        nodelist = list(comsdraw.sort(['pop']).index),
        node_size = sqrt(comsdraw.sort(['pop'])['pop']),
        node_color = comsdraw.sort(['pop'])['com%s'%i])
        
    for n in mg.nodes():
        for m in mg.nodes(): #[find(mg.nodes() == n):len(mg.nodes())]:
            if m == n:
                continue
            else:
                if partition[m] == partition[n]:
                    #comnet.add_edge(m,n)