{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import sys\n", "sys.path.insert(0,'..')\n", "import folium\n", "#import pandas as pd\n", "#folium.initialize_notebook()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#Standard OSM\n", "map_osm = folium.Map(location=[45.5236, -122.6750])\n", "map_osm" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stamen = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner',\n", " zoom_start=13)\n", "stamen" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mt_hood = folium.Map(location=[45.372, -121.6972], zoom_start=12,\n", " tiles='Stamen Terrain')\n", "folium.Marker([45.3288, -121.6625], popup='Mt. Hood Meadows').add_to(mt_hood)\n", "folium.Marker([45.3311, -121.7113], popup='Timberline Lodge', icon=folium.Icon()).add_to(mt_hood)\n", "mt_hood" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "portland = folium.Map(location=[45.5236, -122.6750], tiles='Stamen Toner',\n", " zoom_start=13)\n", "folium.Marker([45.5244, -122.6699], popup='The Waterfront').add_to(portland)\n", "folium.CircleMarker([45.5215, -122.6261], radius=500,\n", " popup='Laurelhurst Park', color='#3186cc',\n", " fill_color='#3186cc').add_to(portland)\n", "portland" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "latlng = folium.Map(location=[46.1991, -122.1889], tiles='Stamen Terrain',\n", " zoom_start=13)\n", "folium.LatLngPopup().add_to(latlng)\n", "latlng" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "waypoints = folium.Map(location=[46.8527, -121.7649], tiles='Stamen Terrain',\n", " zoom_start=13)\n", "folium.Marker([46.8354, -121.7325], popup='Camp Muir').add_to(waypoints)\n", "folium.ClickForMarker().add_to(waypoints)\n", "waypoints" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "polygons = folium.Map(location=[45.5236, -122.6750], zoom_start=13)\n", "\n", "folium.RegularPolygonMarker([45.5012, -122.6655], popup='Ross Island Bridge',\n", " fill_color='#132b5e', number_of_sides=3, radius=10).add_to(polygons)\n", "folium.RegularPolygonMarker([45.5132, -122.6708], popup='Hawthorne Bridge',\n", " fill_color='#45647d', number_of_sides=4, radius=10).add_to(polygons)\n", "folium.RegularPolygonMarker([45.5275, -122.6692], popup='Steel Bridge',\n", " fill_color='#769d96', number_of_sides=6, radius=10).add_to(polygons)\n", "folium.RegularPolygonMarker([45.5318, -122.6745], popup='Broadway Bridge',\n", " fill_color='#769d96', number_of_sides=8, radius=10).add_to(polygons)\n", "polygons" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import vincent\n", "import pandas as pd\n", "import numpy as np\n", "\n", "NOAA_46041 = pd.read_csv(r'NOAA_46041.csv', index_col=3,\n", " parse_dates=True)\n", "NOAA_46050 = pd.read_csv(r'NOAA_46050_WS.csv', index_col=3,\n", " parse_dates=True)\n", "NOAA_46243 = pd.read_csv(r'NOAA_46243.csv', index_col=3,\n", " parse_dates=True)\n", "\n", "NOAA_46041 = NOAA_46041.dropna()\n", "\n", "#Binned wind speeds for NOAA 46050\n", "bins = range(0, 13, 1)\n", "cuts = pd.cut(NOAA_46050['wind_speed_cwind (m/s)'], bins)\n", "ws_binned = pd.Series(\n", " np.histogram(NOAA_46050['wind_speed_cwind (m/s)'], bins=bins)[0],\n", " index=bins[:-1])\n", "\n", "#NOAA 46401 Wave Period\n", "vis1 = vincent.Line(NOAA_46041['dominant_wave_period (s)'],\n", " width=400, height=200)\n", "vis1.axis_titles(x='Time', y='Dominant Wave Period (s)')\n", "vis1.to_json('vis1.json')\n", "\n", "#NOAA 46050 Binned Wind Speed\n", "vis2 = vincent.Bar(ws_binned, width=400, height=200)\n", "vis2.axis_titles(x='Wind Speed (m/s)', y='# of Obs')\n", "vis2.to_json('vis2.json')\n", "\n", "#NOAA 46243 Wave Height\n", "vis3 = vincent.Area(NOAA_46243['significant_wave_height (m)'],\n", " width=400, height=200)\n", "vis3.axis_titles(x='Time', y='Significant Wave Height (m)')\n", "vis3.to_json('vis3.json')\n", "\n", "#Map all buoys\n", "buoy_map = folium.Map(location=[46.3014, -123.7390], zoom_start=7,\n", " tiles='Stamen Terrain')\n", "\n", "popup1 = folium.Popup(max_width=800,\n", " ).add_child(folium.Vega(vis1, width=500, height=250))\n", "folium.RegularPolygonMarker([47.3489, -124.708],\n", " fill_color='#43d9de',\n", " radius=12,\n", " popup=popup1).add_to(buoy_map)\n", "\n", "popup2 = folium.Popup(max_width=800,\n", " ).add_child(folium.Vega(vis2, width=500, height=250))\n", "folium.RegularPolygonMarker([44.639, -124.5339],\n", " fill_color='#43d9de',\n", " radius=12,\n", " popup=popup2).add_to(buoy_map)\n", "\n", "popup3 = folium.Popup(max_width=800,\n", " ).add_child(folium.Vega(vis3, width=500, height=250))\n", "folium.RegularPolygonMarker([46.216, -124.1280],\n", " fill_color='#43d9de',\n", " radius=12,\n", " popup=popup3).add_to(buoy_map)\n", "\n", "buoy_map" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/journois/anaconda3/envs/test/lib/python3.5/site-packages/ipykernel/__main__.py:12: FutureWarning: 'threshold_scale' default behavior has changed. Now you get a linear scale between the 'min' and the 'max' of your data. To get former behavior, use folium.utilities.split_six.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "state_geo = r'us-states.json'\n", "state_unemployment = r'US_Unemployment_Oct2012.csv'\n", "\n", "state_data = pd.read_csv(state_unemployment)\n", "\n", "#Let Folium determine the scale\n", "states = folium.Map(location=[48, -102], zoom_start=3)\n", "states.choropleth(geo_path=state_geo, data=state_data,\n", " columns=['State', 'Unemployment'],\n", " key_on='feature.id',\n", " fill_color='YlGn', fill_opacity=0.7, line_opacity=0.2,\n", " legend_name='Unemployment Rate (%)')\n", "\n", "states" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "states2 = folium.Map(location=[48, -102], zoom_start=3)\n", "states2.choropleth(geo_path=state_geo, data=state_data,\n", " columns=['State', 'Unemployment'],\n", " threshold_scale=[5, 6, 7, 8, 9, 10],\n", " key_on='feature.id',\n", " fill_color='BuPu', fill_opacity=0.7, line_opacity=0.5,\n", " legend_name='Unemployment Rate (%)',\n", " reset=True)\n", "states2" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "county_data = r'us_county_data.csv'\n", "county_geo = r'us_counties_20m_topo.json'\n", "\n", "df = pd.read_csv(county_data, na_values=[' '])\n", "\n", "\n", "colorscale = folium.colormap.linear.YlOrRd.scale(0,50e3)\n", "employed_series = df.set_index('FIPS_Code')['Employed_2011']\n", "\n", "def style_function(feature):\n", " employed = employed_series.get(int(feature['id'][-5:]),None)\n", " return {\n", " 'fillOpacity' : 0.5,\n", " 'weight' : 0,\n", " 'fillColor' : '#black' if employed is None else colorscale(employed)\n", " }\n", "\n", "#Number of employed with auto scale\n", "map_1 = folium.Map(location=[48, -102], tiles='cartodbpositron',\n", " zoom_start=3)\n", "\n", "folium.TopoJson(open(county_geo),\n", " 'objects.us_counties_20m',\n", " style_function=style_function).add_to(map_1)\n", "\n", "map_1" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "colorscale = folium.colormap.linear.YlGnBu.scale(0,30)\n", "employed_series = df.set_index('FIPS_Code')['Unemployment_rate_2011']\n", "\n", "def style_function(feature):\n", " employed = employed_series.get(int(feature['id'][-5:]),None)\n", " return {\n", " 'fillOpacity' : 0.5,\n", " 'weight' : 0,\n", " 'fillColor' : '#black' if employed is None else colorscale(employed)\n", " }\n", "\n", "#Number of employed with auto scale\n", "map_2 = folium.Map(location=[48, -102], tiles='cartodbpositron',\n", " zoom_start=3)\n", "\n", "folium.TopoJson(open(county_geo),\n", " 'objects.us_counties_20m',\n", " style_function=style_function).add_to(map_2)\n", "\n", "map_2" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "colorscale = folium.colormap.linear.PuRd.scale(0,100000)\n", "employed_series = df.set_index('FIPS_Code')['Median_Household_Income_2011'].dropna()\n", "\n", "def style_function(feature):\n", " employed = employed_series.get(int(feature['id'][-5:]),None)\n", " return {\n", " 'fillOpacity' : 0.5,\n", " 'weight' : 0,\n", " 'fillColor' : '#black' if employed is None else colorscale(employed)\n", " }\n", "\n", "#Number of employed with auto scale\n", "map_3 = folium.Map(location=[48, -102], tiles='cartodbpositron',\n", " zoom_start=3)\n", "\n", "folium.TopoJson(open(county_geo),\n", " 'objects.us_counties_20m',\n", " style_function=style_function).add_to(map_3)\n", "\n", "map_3" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.1" } }, "nbformat": 4, "nbformat_minor": 0 }