Largest elements

Links with the largest flow

4069	272	15	W 21 St & 6 Ave	W 22 St & 10 Ave
4111	64	264	Pershing Square North	E 24 St & Park Ave S
4195	359	392	Central Park S & 6 Ave	5 Ave & E 73 St
4290	64	63	Pershing Square North	W 41 St & 8 Ave
4385	358	383	E 85 St & York Ave	E 85 St & 3 Ave
4396	64	143	Pershing Square North	W 33 St & 7 Ave
4648	272	139	W 21 St & 6 Ave	9 Ave & W 22 St
4913	252	173	12 Ave & W 40 St	West St & Chambers St
4989	137	137	Centre St & Chambers St	Centre St & Chambers St
6466	359	453	Central Park S & 6 Ave	5 Ave & E 78 St
11986	359	359	Central Park S & 6 Ave	Central Park S & 6 Ave

The most and the least active stations

> wdir <- 'E:/data/bike/CitiBike/csv/2015-16'
> setwd(wdir)
> T <- read.csv('SO2sp.csv',head=TRUE,sep=';',stringsAsFactors=FALSE)
> T[1,]
  v             Name  sumO  sumI  o0  o1  o2  o3  o4 o5 o6 o7 o8 o9 o10 o11 o12
1 1 W 26 St & 10 Ave 60833 61442 542 388 215 130 124 94 59 56 50 68  65 195 752
  o13 o14  o15  o16  o17  o18  o19  o20  o21  o22  o23  o24  o25  o26  o27  o28
1 874 988 1423 1910 2556 2257 1864 1478 1349 1276 1495 1481 1596 1515 1598 1648
   o29  o30  o31  o32  o33  o34  o35  o36  o37  o38  o39  o40  o41  o42  o43
1 1555 1576 1470 1525 1594 1985 2451 3362 3167 2757 2062 1634 1543 1424 1177
   o44  o45 o46 o47  i0  i1  i2  i3  i4 i5  i6 i7 i8 i9 i10 i11 i12 i13 i14
1 1153 1100 677 575 404 260 193 164 131 85 103 70 63 47  98 236 217 641 769
   i15  i16  i17  i18  i19  i20  i21  i22  i23  i24  i25  i26  i27  i28  i29
1 1039 1699 2306 2157 1739 1390 1288 1307 1525 1471 1524 1591 1678 1645 1687
   i30  i31  i32  i33  i34  i35  i36  i37  i38  i39  i40  i41  i42  i43 i44 i45
1 1829 1864 2027 2644 3185 3364 3410 2926 2329 2013 1605 1531 1175 1024 955 893
  i46 i47
1 627 514
> total <- T$sumO+T$sumI
> tot <- order(total,decreasing=TRUE)
> tot[1:10]
 [1]  64 272  88 173  48  38  40  44 328 142
> total[tot[1:10]]
 [1] 281996 203855 200629 196414 188394 170593 164378 163962 162828 161931
> T[tot[1:10],1:4]
      v                    Name   sumO   sumI
64   64         W 41 St & 8 Ave 143342 138654
272 272 Nassau Ave & Russell St 101487 102368
88   88         W 20 St & 8 Ave  98557 102072
173 173 W 16 St & The High Line  96876  99538
48   48         W 22 St & 8 Ave  92946  95448
38   38         W 45 St & 8 Ave  84821  85772
40   40         W 38 St & 8 Ave  81611  82767
44   44      E 14 St & Avenue B  80797  83165
328 328   E 53 St & Madison Ave  79755  83073
142 142        W 53 St & 10 Ave  81074  80857
> n <- length(tot)
> T[tot[(n-10):n],1:4]
      v                    Name sumO sumI
508 508   Verona Pl & Fulton St    0    2
556 556         E 95 St & 3 Ave    0    2
664 664 Amsterdam Ave & W 79 St    0    2
473 473 Leonard St & Meeker Ave    0    1
502 502               City Hall    0    1
506 506       SSP Tech Workshop    0    1
517 517         3 Ave & E 71 St    0    1
520 520          Adventures NYC    0    1
523 523         9 Ave & W 28 St    0    1
533 533        W 27 St & 10 Ave    0    1
661 661  Coffey St & Conover St    0    1
  [1] "v"    "Name" "sumO" "sumI" "o0"   "o1"   "o2"   "o3"   "o4"   "o5"   "o6"   "o7"   "o8"   "o9"  
 [15] "o10"  "o11"  "o12"  "o13"  "o14"  "o15"  "o16"  "o17"  "o18"  "o19"  "o20"  "o21"  "o22"  "o23" 
 [29] "o24"  "o25"  "o26"  "o27"  "o28"  "o29"  "o30"  "o31"  "o32"  "o33"  "o34"  "o35"  "o36"  "o37" 
 [43] "o38"  "o39"  "o40"  "o41"  "o42"  "o43"  "o44"  "o45"  "o46"  "o47"  "i0"   "i1"   "i2"   "i3"  
 [57] "i4"   "i5"   "i6"   "i7"   "i8"   "i9"   "i10"  "i11"  "i12"  "i13"  "i14"  "i15"  "i16"  "i17" 
 [71] "i18"  "i19"  "i20"  "i21"  "i22"  "i23"  "i24"  "i25"  "i26"  "i27"  "i28"  "i29"  "i30"  "i31" 
 [85] "i32"  "i33"  "i34"  "i35"  "i36"  "i37"  "i38"  "i39"  "i40"  "i41"  "i42"  "i43"  "i44"  "i45" 
 [99] "i46"  "i47" 

Stations with zero inflow or outflow

> m <- pmin(T$sumO,T$sumI)
> sum(m==0)
[1] 25
> T[m==0,1:4]
      v                          Name sumO sumI
442 442 Park Ave & Marcus Garvey Blvd    0  325
448 448                 48 Ave & 5 St    0    3
460 460               E 48 St & 5 Ave    0   10
467 467    Leonard St & Manhattan Ave    0    3
470 470                21 St & 41 Ave    0    3
473 473       Leonard St & Meeker Ave    0    1
474 474               Christ Hospital    0   11
480 480        Broadway & Roebling St    0    8
489 489               E 58 St & 1 Ave    0    6
492 492        University Pl & E 8 St    0   84
494 494       Rivington St & Ridge St    0    4
499 499      Montague St & Clinton St    0    2
501 501        Nassau Ave & Newell St    0    2
502 502                     City Hall    0    1
506 506             SSP Tech Workshop    0    1
508 508         Verona Pl & Fulton St    0    2
515 515              Soissons Landing    0    3
517 517               3 Ave & E 71 St    0    1
520 520                Adventures NYC    0    1
523 523               9 Ave & W 28 St    0    1
533 533              W 27 St & 10 Ave    0    1
543 543               E 89 St & 3 Ave    0    3
556 556               E 95 St & 3 Ave    0    2
661 661        Coffey St & Conover St    0    1
664 664       Amsterdam Ave & W 79 St    0    2
> 

Drawing distributions

>>> import sys, os, json, pickle
>>> wdir = 'E:/data/bike/CitiBike/csv'
>>> cdir = 'c:/users/batagelj/work/python/graph/chart'
>>> os.chdir(wdir)
>>> from datetime import *
>>> import webbrowser
>>> def TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,
   fill='steelblue',xLab=70,yLab=40):
   TQ = [ list(q) for q in tq ]
   js = open(cdir+'/barData.js','w')
   js.write('var barData = '+str(TQ)+';\n')
   js.write('var TQmax = '+str(TQmax)+';\n')
   js.write('var Tmin = '+str(Tmin)+';\n')
   js.write('var Tmax = '+str(Tmax)+';\n')
   js.write('var Width = '+str(w)+';\n')
   js.write('var Height = '+str(h)+';\n')
   js.write('var Title = "'+tit+'";\n')
   js.write('var Rfill = "'+fill+'";\n')
   js.write('var xLab = "'+str(xLab)+'";\n')
   js.write('var yLab = "'+str(yLab)+'";\n')
   js.close()  
   b = webbrowser.get('windows-default')
   b.open(cdir+'/TQchart.html')
 
>>> ena = [ 1,"W 26 St & 10 Ave",542,388,215,130,124,94,59,56,50,68,65,195,752,874,988,1423,1910,2556,2257,1864,1478,1349,1276,1495,1481,1596,1515,1598,1648,1555,1576,1470,1525,1594,1985,2451,3362,3167,2757,2062,1634,1543,1424,1177,1153,1100,677,575,404,260,193,164,131,85,103,70,63,47,98,236,217,641,769,1039,1699,2306,2157,1739,1390,1288,1307,1525,1471,1524,1591,1678,1645,1687,1829,1864,2027,2644,3185,3364,3410,2926,2329,2013,1605,1531,1175,1024,955,893,627,514 ]
>>> f = ena[2:50]
>>> f[0]
542
>>> len(f)
48
>>> max(f)
3362
>>> TQmax = max(f)
>>> Tmin = 0; Tmax = 48
>>> w = 600; h=180; tit = ena[1]
>>> tq = [(i,i+1,v) for i,v in enumerate(f)]
>>> tq
[(0, 1, 542), (1, 2, 388), (2, 3, 215), (3, 4, 130), (4, 5, 124), (5, 6, 94), (6, 7, 59), (7, 8, 56), (8, 9, 50), (9, 10, 68), (10, 11, 65), (11, 12, 195), (12, 13, 752), (13, 14, 874), (14, 15, 988), (15, 16, 1423), (16, 17, 1910), (17, 18, 2556), (18, 19, 2257), (19, 20, 1864), (20, 21, 1478), (21, 22, 1349), (22, 23, 1276), (23, 24, 1495), (24, 25, 1481), (25, 26, 1596), (26, 27, 1515), (27, 28, 1598), (28, 29, 1648), (29, 30, 1555), (30, 31, 1576), (31, 32, 1470), (32, 33, 1525), (33, 34, 1594), (34, 35, 1985), (35, 36, 2451), (36, 37, 3362), (37, 38, 3167), (38, 39, 2757), (39, 40, 2062), (40, 41, 1634), (41, 42, 1543), (42, 43, 1424), (43, 44, 1177), (44, 45, 1153), (45, 46, 1100), (46, 47, 677), (47, 48, 575)]
>>> TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='red')
>>> f = ena[50:]
>>> f[0]
404
>>> len(f)
48
>>> max(f)
3410
>>> tq = [(i,i+1,v) for i,v in enumerate(f)]
>>> TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit)

Reading CSV SO file

import csv
with open('./2015-16/SOsp.csv') as csvf:
   readCSV = csv.reader(csvf, delimiter=';')
   names = []; freqs = []; nodes = []
   head = next(readCSV)
   for row in readCSV:
      node = row[1:3]; nodes.append(node)
      name = row[3:5]; names.append(name)
      freq = [ int(f) for f in row[5:53]]
      freqs.append(freq)
 
longn = [ nu+' -> '+nv for nu,nv in names ]
short = [ u+'->'+v for u,v in nodes ]

Saving clustering in R and reading it in Python

> clu <- file("cls7.clu","w")
> getwd()
[1] "E:/data/bike/CitiBike/csv/2015-16"
> cat(cls7,file=clu)
> close(clu)
>>> with open('./2015-16/cls7.clu', 'r') as clu: data = clu.read()
>>> C = [ int(c) for c in data.split() ]

Computing distributions for clusters

nC = max(C)  # number of clusters
Cnt = [0]*nC
for c in range(nC): Cnt[c] = [0]*48
for i in range(len(C)):
   c = C[i]-1
   for j in range(48): Cnt[c][j] = Cnt[c][j]+freqs[i][j]
Cs = [sum(v) for v in Cnt]

Drawing distributions for clusterings

W3 schools: Colors names.

# clusters of clustering C
Tmin = 0; Tmax = 48; w = 900; h=250
color = ['darkorange', 'darkgreen', 'darkmagenta', 'darkslateblue',
          'firebrick', 'darkcyan', 'darkorchid' ]
for c in range(nC):
   tit = "Leader "+str(c+1); TQmax = max(Cnt[c])
   tq = [(i,i+1,v) for i,v in enumerate(Cnt[c])]
   TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill=color[c])
   nap = input("Naprej ?")
 
# Top 6 flows
Fs = [ (i,sum(v)) for i,v in enumerate(freqs) ]
FS = sorted(Fs, key=lambda t: t[1])
top6 = FS[-6:]; c = 0
for i,s in top6:
   tit = "Top "+str(6-c)+': '+long[i]; TQmax = max(freqs[i])
   tq = [(j,j+1,v) for j,v in enumerate(freqs[i])]
   TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill=color[c],xLab=20,yLab=10)
   nap = input("Naprej ?"); c = c+1

The most active stations / Top 10

import csv
os.chdir('E:/data/bike/CitiBike/csv/2015-16')
with open('SO2sp.csv') as csvf:
   readCSV = csv.reader(csvf, delimiter=';')
   names = []; freqs = []; nodes = []
   head = next(readCSV)
   for row in readCSV:
      node = row[0]; nodes.append(node)
      name = row[1]; names.append(name)
      freq = [ int(f) for f in row[4:]]
      freqs.append(freq)               
short = [ 'S'+v for v in nodes ]
>>> sio = [ (i,sum(v)) for i,v in enumerate(freqs) ]
>>> SIO = sorted(sio, key=lambda t: t[1])
>>> top10 = SIO[-10:]
>>> top10
[(141, 161931), (327, 162828), (43, 163962), (39, 164378), (37, 170593), (47, 188394), (172, 196414), (87, 200629), (271, 203855), (63, 281996)]
>>> top10.reverse()
>>> for i,s in top10: print(names[i],s)
W 41 St & 8 Ave 281996
Nassau Ave & Russell St 203855
W 20 St & 8 Ave 200629
W 16 St & The High Line 196414
W 22 St & 8 Ave 188394
W 45 St & 8 Ave 170593
W 38 St & 8 Ave 164378
E 14 St & Avenue B 163962
E 53 St & Madison Ave 162828
W 53 St & 10 Ave 161931
>>> 
>>> top3 = SIO[-3:]
c = 0
for i,s in top3:
   tit = "Top "+str(3-c)+': '+names[i]; TQmax = max(freqs[i])
   tq = [(j,j+1,v) for j,v in enumerate(freqs[i][:48])]
   TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='red',xLab=20,yLab=10)
   nap = input(tit+" > Naprej ?")
   tq = [(j,j+1,v) for j,v in enumerate(freqs[i][48:])]
   TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='blue',xLab=20,yLab=10)
   nap = input("Naprej ?"); c = c+1

Sizes

>>> SO = [ sum(f[:48]) for f in freqs ]
>>> SI = [ sum(f[48:]) for f in freqs ]
>>> sum(SO)
13266296
>>> sum(SI)
13266296
>>> len(SI)
678

Imbalance out(v)-int(v)

>>> aBa = [ abs(SO[i]-SI[i]) for i in range(len(SI)) ]
>>> aBa = [ (i,abs(SO[i]-SI[i])) for i in range(len(SI)) ]
>>> ABA = sorted(aBa, key=lambda t: t[1])
>>> top10 = ABA[-10:]
>>> top10
[(179, 4978), (354, 5726), (362, 6515), (325, 7403), (42, 7411), (62, 8132), (199, 8327), (142, 10465), (494, 15042), (392, 25965)]
>>> top10.reverse()
>>> for i,s in top10: print(names[i],SO[i],SI[i],SO[i]-SI[i])
5 Ave & E 73 St 60524 34559 25965
Van Vorst Park 29962 14920 15042
8 Ave & W 33 St 57127 67592 -10465
W Broadway & Spring St 15217 23544 -8327
E 51 St & 1 Ave 72651 80783 -8132
E 75 St & 3 Ave 56302 48891 7411
Catherine St & Monroe St 36858 29455 7403
E 45 St & 3 Ave 48116 41601 6515
Water - Whitehall Plaza 71364 65638 5726
6 Ave & Canal St 23473 28451 -4978
>>> top4 = ABA[-4:]
----------------------------------------------------------------------
c = 0
for i,s in top4:
   tit = "Top "+str(4-c)+': '+names[i]; TQmax = max(freqs[i])
   tq = [(j,j+1,v) for j,v in enumerate(freqs[i][:48])]
   TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='red',xLab=20,yLab=10)
   nap = input(tit+" > Naprej ?")
   tq = [(j,j+1,v) for j,v in enumerate(freqs[i][48:])]
   TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='blue',xLab=20,yLab=10)
   nap = input("Naprej ?"); c = c+1

Imbalance fDist

>>> nS = len(SI)
>>> dBa = [ (k,sum(abs(freqs[k][:48][i]-freqs[k][48:][i]) for i in range(48))) for k in range(nS) ]
>>> dBa[392]
(392, 84703)
>>> DBA = sorted(dBa, key=lambda t: t[1])
>>> top10 = DBA[-10:]
>>> top10.reverse()
>>> top10
[(392, 84703), (211, 66453), (42, 51297), (47, 50530), (117, 47893), (354, 45554), (62, 34086), (273, 33865), (261, 32562), (158, 30293)]
>>> for i,s in top10: print(i,names[i],s)
 
392 5 Ave & E 73 St 84703
211 Fulton St & William St 66453
42 E 75 St & 3 Ave 51297
47 W 22 St & 8 Ave 50530
117 E 33 St & 2 Ave 47893
354 Water - Whitehall Plaza 45554
62 E 51 St & 1 Ave 34086
273 W 37 St & 10 Ave 33865
261 Cambridge Pl & Gates Ave 32562
158 E 16 St & Irving Pl 30293
>>> 
top4 = DBA[-4:]
c = 0
for i,s in top4:
   tit = "Top "+str(4-c)+': '+names[i]; TQmax = max(freqs[i])
   tq = [(j,j+1,v) for j,v in enumerate(freqs[i][:48])]
   TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='red',xLab=20,yLab=10)
   nap = input(tit+" > Naprej ?")
   tq = [(j,j+1,v) for j,v in enumerate(freqs[i][48:])]
   TQshow(tq,cdir,TQmax,Tmin,Tmax,w,h,tit,fill='blue',xLab=20,yLab=10)
   nap = input("Naprej ?"); c = c+1
notes/net/bikes/citi2.txt · Last modified: 2016/12/12 05:19 by vlado
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki