wheelchair accessibility




Pay Notebook Creator: Rajwinder Munder0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

Wheelchair Accessible Courts

In [1]:
#CrossCompute
search_address = '11356'
search_count = 7
source_table_path = 'courts.csv'
target_folder = '/tmp'
In [2]:
import pandas as pd
t = pd.read_csv(source_table_path)
t.head()
Out[2]:
<style> .dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; } </style>
Accessible Location Name Num_of_Courts Prop_ID lat lon
0 Y Corner of Balcom Avenue and Dewey Avenue Ferry Point Park NaN X126 40.8157 -73.8298
1 Y E 153 St. & Grand Concourse Franz Sigel Park NaN X047 40.8210 -73.9264
2 Y Holland Ave. & Magenta St. Gun Hill Playground NaN X161 40.8747 -73.8656
3 Y E 158th St. & Ruppert Plaza Macombs NaN X030 40.8279 -73.9287
4 Y Bronx River & Lafayette Aves. Sound View Park NaN X118 40.8143 -73.8655
In [3]:
t = t.dropna(subset=['lat', 'lon'])
In [4]:
t= t[t['Accessible']== 'Y']
In [5]:
t.head()
Out[5]:
<style> .dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; } </style>
Accessible Location Name Num_of_Courts Prop_ID lat lon
0 Y Corner of Balcom Avenue and Dewey Avenue Ferry Point Park NaN X126 40.8157 -73.8298
1 Y E 153 St. & Grand Concourse Franz Sigel Park NaN X047 40.8210 -73.9264
2 Y Holland Ave. & Magenta St. Gun Hill Playground NaN X161 40.8747 -73.8656
3 Y E 158th St. & Ruppert Plaza Macombs NaN X030 40.8279 -73.9287
4 Y Bronx River & Lafayette Aves. Sound View Park NaN X118 40.8143 -73.8655
In [6]:
t.iloc[0]
Out[6]:
Accessible                                              Y
Location         Corner of Balcom Avenue and Dewey Avenue
Name                                     Ferry Point Park
Num_of_Courts                                         NaN
Prop_ID                                              X126
lat                                               40.8157
lon                                              -73.8298
Name: 0, dtype: object
In [7]:
t[['lat', 'lon']][:5]
Out[7]:
<style> .dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; } </style>
lat lon
0 40.8157 -73.8298
1 40.8210 -73.9264
2 40.8747 -73.8656
3 40.8279 -73.9287
4 40.8143 -73.8655
In [8]:
source_latlons = t[['lat', 'lon']].values
In [9]:
source_latlons
Out[9]:
array([[ 40.8157, -73.8298],
       [ 40.821 , -73.9264],
       [ 40.8747, -73.8656],
       [ 40.8279, -73.9287],
       [ 40.8143, -73.8655],
       [ 40.8658, -73.8972],
       [ 40.6131, -73.912 ],
       [ 40.5977, -74.0011],
       [ 40.6126, -74.0126],
       [ 40.5784, -73.9962],
       [ 40.608 , -73.9378],
       [ 40.8466, -73.9406],
       [ 40.8031, -73.958 ],
       [ 40.8074, -73.9573],
       [ 40.8107, -73.9551],
       [ 40.7231, -73.9909],
       [ 40.7221, -73.9914],
       [ 40.7175, -73.9937],
       [ 40.7965, -73.8249],
       [ 40.6734, -73.854 ],
       [ 40.7934, -73.8516],
       [ 40.5687, -74.0912],
       [ 40.8266, -73.8923],
       [ 40.7772, -73.9031],
       [ 40.6817, -73.9595]])
In [10]:
    
import geopy

# Convert address to latitude and longitude
geocode = geopy.GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
search_location = geocode(search_address)
search_latlon = search_location.latitude, search_location.longitude
search_latlon
Out[10]:
(40.7901266, -73.8477874)
In [11]:
import pip
pip.main(['install', 'pysal'])
Requirement already satisfied: pysal in /Users/rajmunder/anaconda3/lib/python3.6/site-packages
Requirement already satisfied: numpy>=1.3 in /Users/rajmunder/anaconda3/lib/python3.6/site-packages (from pysal)
Requirement already satisfied: scipy>=0.11 in /Users/rajmunder/anaconda3/lib/python3.6/site-packages (from pysal)
Out[11]:
0
In [12]:
from pysal.cg import RADIUS_EARTH_MILES
In [13]:
from pysal.cg.kdtree import KDTree
In [14]:
source_tree = KDTree(source_latlons, distance_metric='Arc', radius=RADIUS_EARTH_MILES)
distances, indices = source_tree.query(search_latlon, k=search_count)
print(distances)
print(indices)
[ 0.27083323  1.30896908  1.33658388  1.58611096  2.03823757  2.28389119
  3.15420492]
[20  4  0 18  2 19 22]
In [15]:
selected_t = t.iloc[indices].copy()
selected_t['Distance'] = distances
selected_t
Out[15]:
<style> .dataframe thead tr:only-child th { text-align: right; } .dataframe thead th { text-align: left; } .dataframe tbody tr th { vertical-align: top; } </style>
Accessible Location Name Num_of_Courts Prop_ID lat lon Distance
20 Y Poppenhusen Ave. and 119 St. MacNeil Park 1.0 Q009 40.7934 -73.8516 0.270833
4 Y Bronx River & Lafayette Aves. Sound View Park NaN X118 40.8143 -73.8655 1.308969
0 Y Corner of Balcom Avenue and Dewey Avenue Ferry Point Park NaN X126 40.8157 -73.8298 1.336584
18 Y 3 Ave., 147 St. and E River Francis Lewis Park NaN Q126 40.7965 -73.8249 1.586111
2 Y Holland Ave. & Magenta St. Gun Hill Playground NaN X161 40.8747 -73.8656 2.038238
19 Y North Conduit Ave. between 81 and 82 Sts. Joseph P. Addabbo Playground 1.0 Q094 40.6734 -73.8540 2.283891
22 Y E. 167 St between Southern Blvd. and Simpson St. The Field of Dreams 1.0 X264 40.8266 -73.8923 3.154205
In [16]:
target_path = target_folder + '/map.csv'
selected_t.to_csv(target_path, index=False)
print('map_geotable_path = %s' % target_path)
map_geotable_path = /tmp/map.csv
In [17]:
%matplotlib inline
fig = t.plot()
In [18]:
ax = t.plot()  # s is an instance of Series
fig = ax.get_figure()
In [19]:
ax = selected_t[['Name', 'Distance']].plot(kind = 'bar')
fig = ax.get_figure()
In [20]:
target_path = target_folder + '/x.png'
fig.savefig(target_path)
print('abc_image_path = %s' % target_path)
abc_image_path = /tmp/x.png
In [ ]: