In [1]:
import folium
import pandas as pd

folium.initialize_notebook()



In [2]:
#Standard OSM
map_osm = folium.Map(location=[45.5236, -122.6750])
map_osm


Out[2]:

In [3]:
stamen = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner',
                    zoom_start=13)
stamen


Out[3]:

In [4]:
mt_hood = folium.Map(location=[45.372, -121.6972], zoom_start=12,
                     tiles='Stamen Terrain')
mt_hood.simple_marker([45.3288, -121.6625], popup='Mt. Hood Meadows')
mt_hood.simple_marker([45.3311, -121.7113], popup='Timberline Lodge')
mt_hood


Out[4]:

In [5]:
portland = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner',
                      zoom_start=13)
portland.simple_marker(location=[45.5244, -122.6699], popup='The Waterfront')
portland.circle_marker(location=[45.5215, -122.6261], radius=500,
                       popup='Laurelhurst Park', line_color='#3186cc',
                       fill_color='#3186cc')
portland


Out[5]:

In [6]:
latlng = folium.Map(location=[46.1991, -122.1889], tiles='Stamen Terrain',
                    zoom_start=13)
latlng.lat_lng_popover()
latlng


Out[6]:

In [7]:
waypoints = folium.Map(location=[46.8527, -121.7649], tiles='Stamen Terrain',
                       zoom_start=13)
waypoints.simple_marker(location=[46.8354, -121.7325], popup='Camp Muir')
waypoints.click_for_marker(popup='Waypoint')
waypoints


Out[7]:

In [8]:
polygons = folium.Map(location=[45.5236, -122.6750], zoom_start=13)
polygons.polygon_marker(location=[45.5012, -122.6655], popup='Ross Island Bridge',
                        fill_color='#132b5e', num_sides=3, radius=10)
polygons.polygon_marker(location=[45.5132, -122.6708], popup='Hawthorne Bridge',
                        fill_color='#45647d', num_sides=4, radius=10)
polygons.polygon_marker(location=[45.5275, -122.6692], popup='Steel Bridge',
                        fill_color='#769d96', num_sides=6, radius=10)
polygons.polygon_marker(location=[45.5318, -122.6745], popup='Broadway Bridge',
                        fill_color='#769d96', num_sides=8, radius=10)
polygons


Out[8]:

In [9]:
import vincent
NOAA_46041 = pd.read_csv(r'NOAA_46041.csv', index_col=3,
                         parse_dates=True)
NOAA_46050 = pd.read_csv(r'NOAA_46050_WS.csv', index_col=3,
                         parse_dates=True)
NOAA_46243 = pd.read_csv(r'NOAA_46243.csv', index_col=3,
                         parse_dates=True)

NOAA_46041 = NOAA_46041.dropna()

#Binned wind speeds for NOAA 46050
bins = range(0, 13, 1)
cuts = pd.cut(NOAA_46050['wind_speed_cwind (m/s)'], bins)
ws_binned = pd.value_counts(cuts).reindex(cuts.levels)

#NOAA 46401 Wave Period
vis1 = vincent.Line(NOAA_46041['dominant_wave_period (s)'],
                    width=400, height=200)
vis1.axis_titles(x='Time', y='Dominant Wave Period (s)')
vis1.to_json('vis1.json')

#NOAA 46050 Binned Wind Speed
vis2 = vincent.Bar(ws_binned, width=400, height=200)
vis2.axis_titles(x='Wind Speed (m/s)', y='# of Obs')
vis2.to_json('vis2.json')

#NOAA 46243 Wave Height
vis3 = vincent.Area(NOAA_46243['significant_wave_height (m)'],
                    width=400, height=200)
vis3.axis_titles(x='Time', y='Significant Wave Height (m)')
vis3.to_json('vis3.json')

#Map all buoys
buoy_map = folium.Map(location=[46.3014, -123.7390], zoom_start=7,
                      tiles='Stamen Terrain')
buoy_map.polygon_marker(location=[47.3489, -124.708], fill_color='#43d9de',
                        radius=12, popup=(vis1, 'vis1.json'))
buoy_map.polygon_marker(location=[44.639, -124.5339], fill_color='#43d9de',
                        radius=12, popup=(vis2, 'vis2.json'))
buoy_map.polygon_marker(location=[46.216, -124.1280], fill_color='#43d9de',
                        radius=12, popup=(vis3, 'vis3.json'))
buoy_map.create_map(path='NOAA_buoys.html')
buoy_map.render_iframe = True
buoy_map


Out[9]:

In [10]:
state_geo = r'us-states.json'
state_unemployment = r'US_Unemployment_Oct2012.csv'

state_data = pd.read_csv(state_unemployment)

#Let Folium determine the scale
states = folium.Map(location=[48, -102], zoom_start=3)
states.geo_json(geo_path=state_geo, data=state_data,
                columns=['State', 'Unemployment'],
                key_on='feature.id',
                fill_color='YlGn', fill_opacity=0.7, line_opacity=0.2,
                legend_name='Unemployment Rate (%)')
states.create_map(path='us_state_map.html')
states


Out[10]:

In [11]:
states2 = folium.Map(location=[48, -102], zoom_start=3)
states2.geo_json(geo_path=state_geo, data=state_data,
                 columns=['State', 'Unemployment'],
                 threshold_scale=[5, 6, 7, 8, 9, 10],
                 key_on='feature.id',
                 fill_color='BuPu', fill_opacity=0.7, line_opacity=0.5,
                 legend_name='Unemployment Rate (%)',
                 reset=True)
states2.create_map(path='us_state_map_2.html')
states2


Out[11]:

In [12]:
county_data = r'us_county_data.csv'
county_geo = r'us_counties_20m_topo.json'

#Read into Dataframe, cast to string for consistency
df = pd.read_csv(county_data, na_values=[' '])
df['FIPS_Code'] = df['FIPS_Code'].astype(str)


def set_id(fips):
    '''Modify FIPS code to match GeoJSON property'''
    if fips == '0':
        return None
    elif len(fips) <= 4:
        return ''.join(['0500000US0', fips])
    else:
        return ''.join(['0500000US', fips])

#Apply set_id, drop NaN
df['GEO_ID'] = df['FIPS_Code'].apply(set_id)
df = df.dropna()

#Number of employed with auto scale
map_1 = folium.Map(location=[48, -102], zoom_start=3)
map_1.geo_json(geo_path=county_geo, data_out='data1.json', data=df,
               columns=['GEO_ID', 'Employed_2011'],
               key_on='feature.id',
               fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.3,
               topojson='objects.us_counties_20m')
map_1.create_map(path='map_1.html')
map_1


Out[12]:

In [13]:
map_2 = folium.Map(location=[40, -99], zoom_start=4)
map_2.geo_json(geo_path=county_geo, data_out='data2.json', data=df,
               columns=['GEO_ID', 'Unemployment_rate_2011'],
               key_on='feature.id',
               threshold_scale=[0, 5, 7, 9, 11, 13],
               fill_color='YlGnBu', line_opacity=0.3,
               legend_name='Unemployment Rate 2011 (%)',
               topojson='objects.us_counties_20m')
map_2.create_map(path='map_2.html')
map_2


Out[13]:

In [14]:
map_3 = folium.Map(location=[40, -99], zoom_start=4)
map_3.geo_json(geo_path=county_geo, data_out='data3.json', data=df,
               columns=['GEO_ID', 'Median_Household_Income_2011'],
               key_on='feature.id',
               fill_color='PuRd', line_opacity=0.3,
               legend_name='Median Household Income 2011 ($)',
               topojson='objects.us_counties_20m')
map_3.create_map(path='map_3.html')
map_3


Out[14]: