mgdraw.remove_nodes_from(akhi)

#Projection
project = pyproj.Proj('+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=38.5 +lon_0=-97 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs')
t = project(metros['lon'],metros['lat'])
pos = dict(zip(metros.index,zip(t[0]+width / 2,t[1] + height / 2)))

#colormap = cm = plt.get_cmap('Spectral') 
#######Done with prep########

#Maps of total residuals by metro
sresid = m2m[['source','resid']].groupby('source').agg('sum').sort('resid',ascending = False)
tresid = m2m[['target','resid']].groupby('target').agg('sum').sort('resid',ascending = False)
sres = pd.merge(sresid, metros, left_index = True, right_on = 'id')
tres = pd.merge(tresid, metros, left_index = True, right_on = 'id')
'''
netplot('output/radiation/metro_s_resid.jpeg',width, height, mgdraw, pos, with_labels = False, 
    nodelist = list(sres.sort('pop').index), 
    node_size = sqrt(sres.sort(['pop'])['pop']), 
    node_color = sres.sort(['pop'])['resid'],cmap = colormap,
    alpha = .7, linewidths = 0.5, width = 0)
   ''' 
netplot('output/radiation/metro_t_resid_sdlariv.jpeg',width, height, mgdraw, pos, with_labels = False, 
    nodelist = list(tres.sort('pop').index), 
    node_size = sqrt(tres.sort(['pop'])['pop']), 
    node_color = tres.sort(['pop'])['resid'],
    alpha = .7, linewidths = 0.5, width = 0)
    
tres.to_csv('output/radiation/metro_t_resid_lasdriv.csv')
tres.iloc[0:30].to_csv('output/radiation/metro_t_pos_resid_lasdriv.csv')
tres.sort('resid').iloc[0:30].to_csv('output/radiation/metro_t_neg_resid_lasdriv.csv')
Exemplo n.º 2
0
mgdraw = mg.copy()
mgdraw.remove_nodes_from(akhi)

#Play with projections
project = pyproj.Proj('+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=38.5 +lon_0=-97 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs')

t = project(statsdraw['lon'],statsdraw['lat'])
pos = dict(zip(statsdraw.index,zip(t[0]+width / 2,t[1] + height / 2)))


#Loop through statistics
for stat in ['degree','wdegree','closeness','flowcloseness','btwnness','flowbtwnness']:
    netplot('output/netstats/maps_%s_%s.jpeg' %(stat,year),width, height,mgdraw, pos, with_labels = False, 
    nodelist = list(statsdraw.sort(['pop']).index), 
    node_size = sqrt(statsdraw.sort(['pop'])['pop']), 
    node_color = statsdraw.sort(['pop'])[stat],
    alpha = .7, linewidths = 0.5, width = 0)
    
    stats[['shortname','pop',stat]].sort(stat, ascending = False).iloc[0:20].to_csv('output/netstats/top20_%s_%s.csv' %(stat, year))




#Plot statistics vs each other
plt.plot(stats['pop'],stats['wdegree'], 'bo')
plt.xlabel('Population')
plt.ylabel('Weighted Degree')
plt.savefig('output/correlations/pop_wdegree_%s.pdf' %year)
plt.close()
pearsonr(stats['pop'],stats['wdegree'])
Exemplo n.º 3
0
#Other regionalizations based on states
othercoms = pd.io.parsers.read_csv('data/othercommunities.csv')
comsform2 = pd.merge(comsform, othercoms[['Abbreviation','Court_dist','Census']], how = 'left',left_on = 'state', right_on = 'Abbreviation')
comsform = comsform2
#Export comsform data
comsform.to_csv('output/community_statistics.csv')



metrosdraw = comsform.drop(akhi)

#maps
for stat in ['churnrate','wexmpt','outcom','wdeg', 'wform','outformcom','incom_exmpt','pop','commigpct','wincomdeg', 'partcoef','comzscore']:
    netplot('output/maps_%s.jpeg' %stat,width, height,mgdraw, pos, with_labels = False, 
    nodelist = list(metrosdraw.sort(['pop']).index), 
    node_size = sqrt(metrosdraw.sort(['pop'])['pop']), 
    node_color = metrosdraw.sort(['pop'])[stat],
    alpha = .7, linewidths = 0.5, width = 0)
    
    
netplot('output/maps_%s.jpeg' %'test',width, height,mgdraw, pos, with_labels = False, 
    nodelist = list(metrosdraw[metrosdraw['wexmpt']<100].sort(['pop']).index), 
    node_size = sqrt(metrosdraw[metrosdraw['wexmpt']<100].sort(['pop'])['pop']), 
    node_color = metrosdraw[metrosdraw['wexmpt']<100].sort(['pop'])['wexmpt'],
    alpha = .7, linewidths = 0.5, width = 0)
    
    
netplot('output/maps_%s.jpeg' %'test2',width, height,mgdraw, pos, with_labels = False, 
    nodelist = list(metrosdraw[metrosdraw['wexmpt']>=100].sort(['pop']).index), 
    node_size = sqrt(metrosdraw[metrosdraw['wexmpt']>=100].sort(['pop'])['pop']), 
    node_color = metrosdraw[metrosdraw['wexmpt']>=100].sort(['pop'])['wexmpt'],
Exemplo n.º 4
0
project = pyproj.Proj('+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=38.5 +lon_0=-97 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs')
t = project(metros['lon'],metros['lat'])
pos = dict(zip(metros.index,zip(t[0]+width / 2,t[1] + height / 2)))

colormap = cm = plt.get_cmap('Spectral') 
#######Done with prep########

#Maps of total residuals by metro
sresid = m2m[['source','resid']].groupby('source').agg('sum').sort('resid',ascending = False)
tresid = m2m[['target','resid']].groupby('target').agg('sum').sort('resid',ascending = False)
sres = pd.merge(sresid, metros, left_index = True, right_on = 'id')
tres = pd.merge(tresid, metros, left_index = True, right_on = 'id')

netplot('output/radiation/metro_s_resid.jpeg',width, height, mgdraw, pos, with_labels = False, 
    nodelist = list(sres.sort('pop').index), 
    node_size = sqrt(sres.sort(['pop'])['pop']), 
    node_color = sres.sort(['pop'])['resid'],cmap = colormap,
    alpha = .7, linewidths = 0.5, width = 0)
    
netplot('output/radiation/metro_t_resid.jpeg',width, height, mgdraw, pos, with_labels = False, 
    nodelist = list(tres.sort('pop').index), 
    node_size = sqrt(tres.sort(['pop'])['pop']), 
    node_color = tres.sort(['pop'])['resid'],
    alpha = .7, linewidths = 0.5, width = 0)
    
#Maps of migration efficency by metro = source
m2m[['source','e_0910']].groupby('source').agg(sum).sort('e_0910',ascending = False).iloc[0:10]
m2m[['target','e_0910']].groupby('target').agg(sum).sort('e_0910',ascending = False).iloc[0:10]

outmig = m2m[['source','e_0910']].groupby('source').agg(sum)
inmig = m2m[['target','e_0910']].groupby('target').agg(sum)
Exemplo n.º 5
0
'''

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)
                    comlist.append((m,n))
        
comdf = pd.DataFrame.from_records(comlist)
comdf['cnt'] = 1
comcol = comdf.groupby([0,1]).agg(sum)
comcol = comcol.sort(['cnt'])
Exemplo n.º 6
0
project = pyproj.Proj('+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs')

t = project(statsdraw['lon'],statsdraw['lat'])
pos = dict(zip(statsdraw.index,zip(t[0],t[1])))
pos2 = dict(zip(statsdraw.index,zip(t[0]+3000000,t[1]+2000000)))

#Basemap

m = bm.Basemap(width = 6000000, height = 4000000, projection = 'aea', resolution = 'l', lat_1 = 20, lat_2 = 60, lat_0 = 40, lon_0 = -96)
m.drawcountries()
m.drawcoastlines()
#m.drawstates()
plt.show()

nx.draw(mgdraw,pos2,with_labels = False,alpha = 1, linewidths = 0.5, width = 0,
        nodelist = list(statsdraw.sort(['pop']).index),
        node_size = sqrt(statsdraw.sort(['pop'])['pop'])/3,
        node_color = statsdraw.sort(['pop'])['wdegree'])







netplot('output/projectedtest.jpeg', mg, pos, with_labels = False, nodelist = list(metros.index), node_size = metros['pop'] / 50000, alpha = .4, linewidths = 0, width = .1)

nx.draw(mg, pos = pos, with_labels = False, nodelist = list(metros.index), node_size = metros['pop'] / 50000, alpha = .4, linewidths = 0, width = .1)

netplot('output/projectedtest.jpeg', mg, pos, with_labels = False, nodelist = list(metros.index), node_size = metros['pop'] / 50000, alpha = .4, linewidths = 0, width = .1)