Susan Kum, Ph.D. is a researcher at the NYU School of Medicine who proposed and created the first prototype of this tool.
{ organization_table : Organizations ? Upload a CSV of organizations or edit the table below }
{ language_select : Language Spoken ? Filter by language spoken at the organization }
{ target_address : Target Address ? Specify an address around which you would like to search }
{ search_radius_in_miles : Search Radius in Miles ? Show only organizations within the search radius }
# Press the Blue Button to preview this as a CrossCompute Tool
organization_table_path = 'organizations.csv'
language_select_path = 'languages.txt'
target_address = '5616 6th Avenue, Brooklyn, NY'
search_radius_in_miles = 5
target_folder = '/tmp'
from pandas import read_csv
organization_table = read_csv(organization_table_path)
organization_table[:2]
import requests
from pandas import Series
base_url = 'https://api.cityofnewyork.us/geoclient/v1/address.json'
geoclient_id = '89f55ba2'
geoclient_key = '3c19c2a1701bf0814a81acb99782f8ea'
def expand_row(row):
house_number, _, street_name = row['Address'].partition(' ')
borough_name = row['Borough']
response = requests.get(base_url, {
'houseNumber': house_number,
'street': street_name,
'borough': borough_name,
'app_id': geoclient_id,
'app_key': geoclient_key,
})
response_json = response.json()
d = response_json['address']
return Series([
d['zipCode'], d['communityDistrict'],
d['censusTract2010'], d['censusBlock2010'],
d['censusTract2000'], d['censusBlock2000'],
d['nta'], d['ntaName'],
d['buildingIdentificationNumber'],
d['latitude'], d['longitude'],
d['xCoordinate'], d['yCoordinate']])
geoclient_table = organization_table.apply(expand_row, axis=1)
geoclient_table.columns = [
'ZipCode', 'CommunityDistrict',
'2010CensusTract', '2010CensusBlock',
'2000CensusTract', '2000CensusBlock',
'NeighborhoodCode', 'NeighborhoodName',
'BuildingIdNumber',
'Latitude', 'Longitude',
'XCoordinate', 'YCoordinate',
]
table = organization_table.join(geoclient_table)
table[:2]
selected_languages = open(language_select_path, 'rt').read().splitlines()
selected_languages
def filter_row_by_language(row):
value = row['Language']
return all(x in value for x in selected_languages)
mask = table.apply(filter_row_by_language, axis=1, reduce=True)
filtered_table = table[mask]
filtered_table
import geopy
geocode = geopy.GoogleV3(api_key='AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w', timeout=3).geocode
target_location = geocode(target_address)
target_latlon = target_location.latitude, target_location.longitude
target_latlon
from geopy.distance import vincenty as get_distance
def filter_row_by_distance(row):
source_latlon = row['Latitude'], row['Longitude']
return get_distance(source_latlon, target_latlon).miles < search_radius_in_miles
mask = filtered_table.apply(filter_row_by_distance, axis=1, reduce=True)
nearby_filtered_table = filtered_table[mask]
nearby_filtered_table
from os.path import join
target_path = join(target_folder, 'selected-organizations.csv')
nearby_filtered_table.to_csv(target_path, index=False)
print('selected_organization_count = %s' % len(nearby_filtered_table))
print('selected_organization_table_path = %s' % target_path)
print('selected_organization_geotable_path = %s' % target_path)